@tryghost/mg-blogger 0.11.7 → 0.12.0-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.
@@ -1,17 +1,12 @@
1
- import {basename} from 'node:path';
2
- import {domUtils, cardUtils} from '@tryghost/mg-utils';
1
+ import { basename } from 'node:path';
2
+ import { domUtils, cardUtils } from '@tryghost/mg-utils';
3
3
  import autop from 'autop';
4
4
  import sanitizeHtml from 'sanitize-html';
5
- import {slugify} from '@tryghost/string';
6
- import errors from '@tryghost/errors';
7
5
  import SimpleDom from 'simple-dom';
8
-
9
- const {serializeChildren, replaceWith, wrap} = domUtils;
10
-
6
+ const { serializeChildren, replaceWith, wrap } = domUtils;
11
7
  const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
12
8
  const imageCard = cardUtils.getCard('image');
13
-
14
- const cleanExcerpt = htmlContent => {
9
+ const cleanExcerpt = (htmlContent) => {
15
10
  // Convert to text only
16
11
  const cleanedContent = sanitizeHtml(htmlContent, {
17
12
  allowedTags: ['b', 'i', 'em', 'strong', 'a'],
@@ -19,15 +14,12 @@ const cleanExcerpt = htmlContent => {
19
14
  a: ['href', 'title', 'rel', 'target']
20
15
  }
21
16
  });
22
-
23
17
  return cleanedContent.trim();
24
18
  };
25
-
26
- const slugFromURL = url => {
19
+ const slugFromURL = (url) => {
27
20
  return url.split('/').pop().replace('.html', '');
28
21
  };
29
-
30
- const increaseImageSize = src => {
22
+ const increaseImageSize = (src) => {
31
23
  // Increases the image size and removes special flags
32
24
  // https://developers.google.com/photos/library/guides/access-media-items
33
25
  let updatedSrc = src.replace(/\/s[0-9]{2,5}(-[a-z0-9#,*]{1,4})?/g, '/s2000');
@@ -36,149 +28,93 @@ const increaseImageSize = src => {
36
28
  updatedSrc = updatedSrc.replace(/=w[0-9]{2,5}-h[0-9]{2,5}(-[a-z0-9#,*]{1,4})?/g, '=w2000-h2000');
37
29
  return updatedSrc;
38
30
  };
39
-
40
- const handleFirstImage = args => {
41
- let {postData, html} = args;
42
-
31
+ /** A Blogger image file name without its size segment, such as `-s320` or `=w640-h480`. */
32
+ const withoutSize = (name) => name.replace(/(.*)((-=|-|=)w[0-9]{2,5}-h[0-9]{2,5}|(-=|-|=)s[0-9]{2,5})/, '$1');
33
+ /**
34
+ * Use a leading image as the feature image and remove it from the content: an `<img>` that is the first element, or
35
+ * a first element with no text whose image is unlinked or links to the same image at another size.
36
+ */
37
+ const handleFirstImage = ({ postData, html }) => {
43
38
  return domUtils.processFragment(html, parsed => {
44
39
  const firstContentElement = parsed.body.children[0];
45
-
46
- if (!firstContentElement) {
47
- postData.html = parsed.html().trim();
48
- return postData;
49
- }
50
-
51
- if (firstContentElement.tagName === 'IMG') {
40
+ if (firstContentElement?.tagName === 'IMG') {
52
41
  postData.feature_image = firstContentElement.getAttribute('src');
53
42
  firstContentElement.remove();
54
- } else if ((firstContentElement.textContent || '').trim() === '') {
55
- const img = firstContentElement.querySelector('img');
56
- const a = firstContentElement.querySelector('a');
57
- const firstContentElementImgSrc = img?.getAttribute('src') ?? null;
58
- const firstContentElementImgBasename = firstContentElementImgSrc
59
- ? basename(firstContentElementImgSrc)
60
- : null;
61
- const firstContentElementAHref = a?.getAttribute('href') ?? null;
62
- const firstContentElementAHrefBasename = firstContentElementAHref
63
- ? basename(firstContentElementAHref)
64
- : null;
65
-
66
- if (firstContentElementImgBasename === firstContentElementAHrefBasename) {
67
- firstContentElement.remove();
68
- postData.feature_image = firstContentElementImgSrc;
69
- } else if (firstContentElementImgSrc && !firstContentElementAHref) {
43
+ }
44
+ else if (firstContentElement && (firstContentElement.textContent || '').trim() === '') {
45
+ const imgSrc = firstContentElement.querySelector('img')?.getAttribute('src');
46
+ const aHref = firstContentElement.querySelector('a')?.getAttribute('href');
47
+ // A first element without an image, such as an embed, stays in the content.
48
+ if (imgSrc &&
49
+ (!aHref ||
50
+ basename(imgSrc) === basename(aHref) ||
51
+ withoutSize(basename(imgSrc)) === withoutSize(basename(aHref)))) {
70
52
  firstContentElement.remove();
71
- postData.feature_image = firstContentElementImgSrc;
72
- } else {
73
- const firstContentElementImgBasenameNoSize = firstContentElementImgBasename.replace(
74
- /(.*)((-=|-|=)w[0-9]{2,5}-h[0-9]{2,5}|(-=|-|=)s[0-9]{2,5})/,
75
- '$1'
76
- );
77
- const firstContentElementAHrefBasenameNoSize = firstContentElementAHrefBasename.replace(
78
- /(.*)((-=|-|=)w[0-9]{2,5}-h[0-9]{2,5}|(-=|-|=)s[0-9]{2,5})/,
79
- '$1'
80
- );
81
-
82
- if (firstContentElementImgBasenameNoSize === firstContentElementAHrefBasenameNoSize) {
83
- firstContentElement.remove();
84
- postData.feature_image = firstContentElementImgSrc;
85
- }
53
+ postData.feature_image = imgSrc;
86
54
  }
87
55
  }
88
-
89
56
  postData.html = parsed.html().trim();
90
57
  return postData;
91
58
  });
92
59
  };
93
-
94
- const processHTMLContent = async args => {
95
- let {postData, html, options} = args;
96
-
60
+ const processHTMLContent = async ({ postData, html, options }) => {
97
61
  html = autop(html);
98
-
99
62
  html = domUtils.processFragment(html, parsed => {
100
63
  parsed.$('div.separator').forEach(el => {
101
64
  replaceWith(el, `<hr><div>${serializeChildren(el).trim()}</div>`);
102
65
  });
103
-
104
- parsed.$('img').forEach(el => {
105
- const imgSrc = el.getAttribute('src');
106
- const largerSrc = increaseImageSize(imgSrc);
107
-
66
+ parsed.$('img[src]').forEach(el => {
67
+ const largerSrc = increaseImageSize(el.getAttribute('src'));
108
68
  el.setAttribute('src', largerSrc);
109
69
  el.removeAttribute('width');
110
70
  el.removeAttribute('height');
111
71
  });
112
-
113
72
  parsed.$('.tr-caption-container').forEach(el => {
114
73
  const img = el.querySelector('img');
115
74
  const imgParentA = img?.closest('a');
116
- const hasLink = !!imgParentA;
117
- const href = hasLink ? imgParentA.getAttribute('href') : null;
118
- const imgSrc = img?.getAttribute('src') ?? null;
75
+ const href = imgParentA?.getAttribute('href');
76
+ const imgSrc = img?.getAttribute('src');
119
77
  const captionEl = el.querySelector('.tr-caption');
120
78
  const caption = captionEl ? serializeChildren(captionEl) : '';
121
79
  const cleanedExcerpt = cleanExcerpt(caption);
122
-
123
- if (!imgSrc || imgSrc.length === 0) {
80
+ if (!imgSrc) {
124
81
  return;
125
82
  }
126
-
127
83
  // Update image size so we get the biggest image
128
84
  const updatedImgSrc = increaseImageSize(imgSrc);
129
-
130
- let cardOpts = {
131
- env: {dom: new SimpleDom.Document()},
85
+ const cardOpts = {
86
+ env: { dom: new SimpleDom.Document() },
132
87
  payload: {
133
88
  src: updatedImgSrc,
134
89
  caption: cleanedExcerpt
135
90
  }
136
91
  };
137
-
138
- if (hasLink) {
139
- const updatedHref = increaseImageSize(href);
140
-
141
- if (updatedImgSrc !== updatedHref) {
142
- cardOpts.payload.href = href;
143
- }
92
+ if (href && updatedImgSrc !== increaseImageSize(href)) {
93
+ cardOpts.payload.href = href;
144
94
  }
145
-
146
95
  const newCard = serializer.serialize(imageCard.render(cardOpts));
147
-
148
96
  replaceWith(el, newCard);
149
97
  });
150
-
151
- parsed.$('a > img').forEach(el => {
98
+ parsed.$('a[href] > img[src]').forEach(el => {
152
99
  const parentA = el.parentElement;
153
- if (!parentA || parentA.tagName !== 'A') {
154
- return;
155
- }
156
-
157
100
  const aHref = parentA.getAttribute('href');
158
101
  const imgSrc = el.getAttribute('src');
159
-
160
- const updatedaHref = increaseImageSize(aHref);
161
- const updatedImgSrc = increaseImageSize(imgSrc);
162
-
163
102
  // Don't touch Koenig cards
164
103
  if (parentA.getAttribute('class')?.includes('kg-') || el.getAttribute('class')?.includes('kg-')) {
165
104
  return;
166
105
  }
167
-
168
- if (updatedaHref === updatedImgSrc) {
106
+ if (increaseImageSize(aHref) === increaseImageSize(imgSrc)) {
169
107
  replaceWith(parentA, `<img src="${imgSrc}">`);
170
108
  }
171
109
  });
172
-
173
110
  // Convert weird lists to real lists
174
111
  parsed.$('span[style*="white-space: pre"]').forEach(el => {
175
112
  const parentDiv = el.closest('div');
176
113
  if (!parentDiv) {
177
114
  return;
178
115
  }
179
-
180
116
  const parentHTML = serializeChildren(parentDiv);
181
- if (parentHTML.includes('•') || parentHTML.includes('&#x2022;')) {
117
+ if (parentHTML.includes('•')) {
182
118
  // Change div to li by replacing with a new li element
183
119
  const newLi = parsed.document.createElement('li');
184
120
  // Move the div's child nodes into the li. The div is replaced
@@ -212,223 +148,82 @@ const processHTMLContent = async args => {
212
148
  replaceWith(parentDiv, newLi);
213
149
  }
214
150
  });
215
-
216
151
  // Wrap <li>s in <ul>
217
152
  parsed.$('li').forEach(el => {
218
153
  const prevSibling = el.previousElementSibling;
219
154
  if (prevSibling && prevSibling.tagName === 'UL') {
220
155
  prevSibling.appendChild(el);
221
- } else {
156
+ }
157
+ else {
222
158
  wrap(el, '<ul></ul>');
223
159
  }
224
160
  });
225
-
226
161
  parsed
227
162
  .$('div[style*="color"][style*="font-family"][style*="font-size"][style*="white-space: pre-line"]')
228
163
  .forEach(el => {
229
- replaceWith(el, `<p>${serializeChildren(el).trim()}</p>`);
230
- });
231
-
164
+ replaceWith(el, `<p>${serializeChildren(el).trim()}</p>`);
165
+ });
232
166
  parsed
233
- .$(
234
- 'span[style*="background-color"][style*="color"][style*="font-family"][style*="font-size"][style*="white-space: pre-line"]'
235
- )
167
+ .$('span[style*="background-color"][style*="color"][style*="font-family"][style*="font-size"][style*="white-space: pre-line"]')
236
168
  .forEach(el => {
237
- replaceWith(el, `<p>${serializeChildren(el).trim()}</p>`);
238
- });
239
-
169
+ replaceWith(el, `<p>${serializeChildren(el).trim()}</p>`);
170
+ });
240
171
  parsed.$('div[style="text-align: center;"]').forEach(el => {
241
172
  replaceWith(el, `<p>${serializeChildren(el).trim()}</p>`);
242
173
  });
243
-
244
174
  parsed.$('h1, h2, h3, h4, h5, h6').forEach(el => {
245
175
  const styleAttr = el.getAttribute('style');
246
176
  if (styleAttr === 'text-align: left;') {
247
177
  el.removeAttribute('style');
248
178
  }
249
179
  });
250
-
251
180
  parsed.$('h3 b').forEach(el => {
252
181
  replaceWith(el, serializeChildren(el));
253
182
  });
254
-
255
183
  parsed.$('div, p').forEach(el => {
256
184
  const attrs = el.attributes;
257
185
  const children = el.children;
258
-
259
186
  if (serializeChildren(el).trim() === '' && attrs.length === 0) {
260
187
  el.remove();
261
- } else if (serializeChildren(el) === '&#xA0;') {
262
- el.remove();
263
- } else if (attrs.length === 0 && children.length === 1 && children[0].tagName === 'IMG') {
188
+ }
189
+ else if (attrs.length === 0 && children.length === 1 && children[0].tagName === 'IMG') {
264
190
  replaceWith(el, serializeChildren(el).trim());
265
191
  }
266
192
  });
267
-
268
193
  parsed.$('p').forEach(el => {
269
194
  const innerHtml = serializeChildren(el);
270
- if (innerHtml.trim() === '' || innerHtml === '&#xA0;' || innerHtml.trim() === '&nbsp;') {
195
+ if (innerHtml.trim() === '' || innerHtml.trim() === '&nbsp;') {
271
196
  el.remove();
272
197
  }
273
198
  });
274
-
275
199
  parsed.$('div').forEach(el => {
276
200
  const attrs = el.attributes;
277
201
  const children = el.children;
278
-
279
202
  if (attrs.length === 0 && children.length === 0) {
280
203
  replaceWith(el, `<p>${serializeChildren(el).trim()}</p>`);
281
204
  }
282
205
  });
283
-
284
206
  parsed.$('iframe[src*="youtube.com"]').forEach(el => {
285
207
  el.setAttribute('width', '160');
286
208
  el.setAttribute('height', '90');
287
209
  });
288
-
289
210
  // Convert back to plain HTML
290
211
  return parsed.html();
291
212
  });
292
-
293
213
  // Trim whitespace
294
214
  html = html.trim();
295
-
296
215
  // Remove first element(s) if <hr>
297
216
  html = html.replace(/^(<hr\/?> ?)+/gm, '').trim();
298
-
299
217
  // Remove empty attributes
300
218
  html = html.replace(/=""/g, '');
301
-
302
219
  postData.html = html;
303
-
304
220
  if (options?.firstImageAsFeatured) {
305
221
  postData = handleFirstImage({
306
222
  postData,
307
223
  html
308
224
  });
309
225
  }
310
-
311
226
  return postData;
312
227
  };
313
-
314
- const processPost = async (postData, options) => {
315
- const {addTag} = options;
316
-
317
- const post = {
318
- url: postData.url,
319
- data: {
320
- slug: slugFromURL(postData.url),
321
- title: postData.title,
322
- status: 'published',
323
- published_at: new Date(postData.published),
324
- created_at: new Date(postData.published),
325
- updated_at: new Date(postData.updated),
326
- type: 'post',
327
- tags: []
328
- }
329
- };
330
-
331
- post.data = await processHTMLContent({
332
- postData: post.data,
333
- html: postData.content,
334
- options
335
- });
336
-
337
- if (postData.author) {
338
- const authorName = postData.author.displayName.replace('&amp;', '&');
339
- const authorSlug = slugify(authorName);
340
-
341
- post.data.author = {
342
- url: `migrator-added-author-${authorSlug}`,
343
- data: {
344
- slug: authorSlug,
345
- email: `${authorSlug}@example.com`,
346
- name: authorName
347
- }
348
- };
349
- }
350
-
351
- if (postData.labels) {
352
- postData.labels.forEach(label => {
353
- const cleanedLabel = label.replace('&amp;', '&');
354
- const labelSlug = slugify(cleanedLabel);
355
-
356
- post.data.tags.push({
357
- url: `migrator-added-tag-${labelSlug}`,
358
- data: {
359
- slug: labelSlug,
360
- name: cleanedLabel
361
- }
362
- });
363
- });
364
- }
365
-
366
- if (addTag) {
367
- const addTagSlug = slugify(addTag);
368
-
369
- post.data.tags.push({
370
- url: `migrator-added-tag-${addTagSlug}`,
371
- data: {
372
- slug: addTagSlug,
373
- name: addTag
374
- }
375
- });
376
- }
377
-
378
- if (postData?.blog?.id) {
379
- post.data.tags.push({
380
- url: `migrator-added-tag-site-id${postData.blog.id}`,
381
- data: {
382
- slug: `hash-blogger-site-${postData.blog.id}`,
383
- name: `#blogger-site-${postData.blog.id}`
384
- }
385
- });
386
- }
387
-
388
- post.data.tags.push({
389
- url: 'migrator-added-tag',
390
- data: {
391
- slug: 'hash-blogger',
392
- name: '#blogger'
393
- }
394
- });
395
-
396
- return post;
397
- };
398
-
399
- const processPosts = async (posts, options) => {
400
- // Filter out falsy items in the post list
401
- posts = posts.filter(i => i);
402
-
403
- const results = [];
404
-
405
- for (let i = 0; i < posts.length; i++) {
406
- results.push(await processPost(posts[i], options));
407
- }
408
-
409
- return results;
410
- };
411
-
412
- const all = async (input, {options}) => {
413
- const output = {
414
- posts: [],
415
- users: []
416
- };
417
-
418
- if (input.length < 1) {
419
- return new errors.NoContentError({message: 'Input file is empty'});
420
- }
421
-
422
- output.posts = await processPosts(input.posts, options);
423
-
424
- return output;
425
- };
426
-
427
- export default {
428
- processHTMLContent,
429
- processPost,
430
- processPosts,
431
- all
432
- };
433
-
434
- export {cleanExcerpt, slugFromURL, increaseImageSize};
228
+ export { cleanExcerpt, slugFromURL, increaseImageSize, processHTMLContent };
229
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/lib/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC;AACnC,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,EAAC,iBAAiB,EAAE,WAAW,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC;AAExD,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACnE,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAe7C,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAU,EAAE;IACjD,uBAAuB;IACvB,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,EAAE;QAC7C,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC;QAC5C,iBAAiB,EAAE;YACf,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;SACxC;KACJ,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC,IAAI,EAAE,CAA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1
+ /** A post from the Blogger API's `GET /blogger/v3/blogs/:blogId/posts`. */
2
+ export interface BloggerPost {
3
+ kind?: string;
4
+ id: string;
5
+ blog?: {
6
+ id?: string;
7
+ };
8
+ /** RFC 3339, with the blog's UTC offset. */
9
+ published?: string;
10
+ updated?: string;
11
+ url?: string;
12
+ title?: string;
13
+ content?: string;
14
+ author?: {
15
+ id?: string;
16
+ displayName?: string;
17
+ url?: string;
18
+ };
19
+ labels?: string[];
20
+ [key: string]: unknown;
21
+ }
22
+ /** Options applied when mapping stored Blogger posts. */
23
+ export interface BloggerOptions {
24
+ /** Map only the posts of these stored blogs. Defaults to every stored blog. */
25
+ blogID?: string[] | null;
26
+ /** A tag added to every post. */
27
+ addTag?: string | null;
28
+ /** Use a leading image as the post's feature image. Defaults to `true`. */
29
+ firstImageAsFeatured?: boolean;
30
+ [key: string]: any;
31
+ }
@@ -0,0 +1,4 @@
1
+ /* c8 ignore start */
2
+ export {};
3
+ /* c8 ignore stop */
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,qBAAqB;;AA4BrB,oBAAoB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,108 @@
1
+ import assert from 'node:assert/strict';
2
+ import { afterEach, beforeEach, describe, it } from 'node:test';
3
+ import nock from 'nock';
4
+ import { pageRecords, postsURL, tasks } from '../lib/fetch.js';
5
+ import { BLOG, KEY, OTHER, apiPost, blogger } from './helpers.js';
6
+ async function all(items) {
7
+ const result = [];
8
+ for await (const item of items) {
9
+ result.push(item);
10
+ }
11
+ return result;
12
+ }
13
+ const options = { apiKey: KEY, blogIDs: [BLOG], requestDelay: 0 };
14
+ describe('Blogger API fetch tasks', () => {
15
+ beforeEach(() => nock.disableNetConnect());
16
+ afterEach(() => {
17
+ nock.cleanAll();
18
+ nock.enableNetConnect();
19
+ });
20
+ it('builds the posts URL with the API key and page token', () => {
21
+ assert.equal(postsURL(BLOG, 'a b'), `https://www.googleapis.com/blogger/v3/blogs/${BLOG}/posts?key=a+b`);
22
+ assert.equal(postsURL(BLOG, KEY, 'next'), `https://www.googleapis.com/blogger/v3/blogs/${BLOG}/posts?key=${KEY}&pageToken=next`);
23
+ });
24
+ it('keys records by post ID, with their blog and page', () => {
25
+ const records = pageRecords(BLOG, [apiPost('1'), { id: '' }], 2);
26
+ assert.deepEqual(records.map(record => [record.kind, record.key, record.format, record.metadata]), [
27
+ ['post', 'post:id:1', 'json', { blog: BLOG, page: 2 }],
28
+ ['post', null, 'json', { blog: BLOG, page: 2 }]
29
+ ]);
30
+ assert.equal(JSON.parse(records[0].content).title, 'Post 1');
31
+ });
32
+ it('yields one task per page, following page tokens blog by blog', async () => {
33
+ const requests = blogger({ [BLOG]: [[apiPost('1')], [apiPost('2')]], [OTHER]: [[apiPost('3')]] });
34
+ const seen = [];
35
+ for await (const task of tasks({ ...options, blogIDs: [BLOG, OTHER] })) {
36
+ const records = await task.records();
37
+ // A page is requested once, however often its records are read.
38
+ await task.records();
39
+ seen.push([task.title, records[0].key, task.page]);
40
+ }
41
+ assert.deepEqual(seen, [
42
+ [`Fetching posts for blog ${BLOG}, page 1`, 'post:id:1', 1],
43
+ [`Fetching posts for blog ${BLOG}, page 2`, 'post:id:2', 2],
44
+ [`Fetching posts for blog ${OTHER}, page 1`, 'post:id:3', 1]
45
+ ]);
46
+ assert.deepEqual(requests, [`${BLOG}?`, `${BLOG}?&pageToken=2`, `${OTHER}?`]);
47
+ });
48
+ it('fetches the next page token itself when a task was not run', async () => {
49
+ const requests = blogger({ [BLOG]: [[apiPost('1')], [apiPost('2')]] });
50
+ const list = await all(tasks(options));
51
+ assert.deepEqual(list.map(task => task.page), [1, 2]);
52
+ assert.deepEqual(requests, [`${BLOG}?`, `${BLOG}?&pageToken=2`]);
53
+ assert.deepEqual((await list[1].records()).map(record => record.key), ['post:id:2']);
54
+ assert.equal(requests.length, 2);
55
+ });
56
+ it('reads a page without items as empty', async () => {
57
+ nock('https://www.googleapis.com')
58
+ .get(`/blogger/v3/blogs/${BLOG}/posts`)
59
+ .query(true)
60
+ .reply(200, { kind: 'blogger#postList', nextPageToken: '' });
61
+ const list = await all(tasks(options));
62
+ assert.equal(list.length, 1);
63
+ assert.deepEqual(await list[0].records(), []);
64
+ });
65
+ it('waits before each request by default', async () => {
66
+ blogger({ [BLOG]: [[apiPost('1')]] });
67
+ const started = Date.now();
68
+ const [task] = await all(tasks({ apiKey: KEY, blogIDs: [BLOG] }));
69
+ assert.ok(Date.now() - started >= 450);
70
+ assert.equal((await task.records()).length, 1);
71
+ });
72
+ it('writes only inside a source ingestion', async () => {
73
+ blogger({ [BLOG]: [[apiPost('1')]] });
74
+ const { value: task } = (await tasks(options).next());
75
+ await assert.rejects(task.task({}), /run them inside context\.sources\.ingest\(\)/);
76
+ });
77
+ it('reports API errors without the API key', async () => {
78
+ blogger({});
79
+ await assert.rejects(all(tasks(options)), (error) => {
80
+ assert.equal(error.message, `Failed to fetch Blogger content for blog ${BLOG}: 404 Blog not found`);
81
+ assert.doesNotMatch(error.message, new RegExp(KEY));
82
+ return true;
83
+ });
84
+ nock.cleanAll();
85
+ nock('https://www.googleapis.com').get(`/blogger/v3/blogs/${BLOG}/posts`).query(true).reply(403, {});
86
+ await assert.rejects(all(tasks(options)), /for blog 12345678: 403 Forbidden$/);
87
+ });
88
+ it('reports unreadable responses and network failures', async () => {
89
+ nock('https://www.googleapis.com')
90
+ .get(`/blogger/v3/blogs/${BLOG}/posts`)
91
+ .query(true)
92
+ .reply(502, '<html>Bad gateway</html>');
93
+ await assert.rejects(all(tasks(options)), (error) => {
94
+ assert.equal(error.message, `Failed to fetch Blogger content for blog ${BLOG}: 502 Bad Gateway`);
95
+ return true;
96
+ });
97
+ nock.cleanAll();
98
+ nock('https://www.googleapis.com')
99
+ .get(`/blogger/v3/blogs/${BLOG}/posts`)
100
+ .query(true)
101
+ .replyWithError('socket hang up');
102
+ await assert.rejects(all(tasks(options)), (error) => {
103
+ assert.equal(error.message, `Failed to fetch Blogger content for blog ${BLOG}`);
104
+ return true;
105
+ });
106
+ });
107
+ });
108
+ //# sourceMappingURL=fetch.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.test.js","sourceRoot":"","sources":["../../src/test/fetch.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AAC9D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAiB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAEhE,KAAK,UAAU,GAAG,CAAI,KAAuB;IACzC,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,OAAO,GAAG,EAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC,EAAC,CAAC;AAEhE,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACrC,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC3C,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC5D,MAAM,CAAC,KAAK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AAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { MigrateContext } from '@tryghost/mg-context';
2
+ import type { BloggerPost } from '../lib/types.js';
3
+ export declare const KEY = "test-key";
4
+ export declare const BLOG = "12345678";
5
+ export declare const OTHER = "87654321";
6
+ /** The three posts in the original API response fixture. */
7
+ export declare const fixture: BloggerPost[];
8
+ /** An API post with every field the mapper reads, overridden by `values`. */
9
+ export declare function apiPost(id: string, values?: Record<string, any>): BloggerPost;
10
+ /**
11
+ * Serve each blog's pages of posts from the posts endpoint, chained by page tokens, requiring the API key. Returns
12
+ * the requested paths and query strings.
13
+ */
14
+ export declare function blogger(blogs: Record<string, BloggerPost[][]>): string[];
15
+ export declare function memoryContext(): Promise<MigrateContext>;
16
+ /** A context holding each blog's posts as completed source data, without fetching. */
17
+ export declare function stored(blogs: Record<string, BloggerPost[]>, metadata?: Record<string, any>): Promise<MigrateContext>;
18
+ export declare function events(context: MigrateContext, type: string): {
19
+ details: Record<string, any>;
20
+ }[];