@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.
@@ -0,0 +1,214 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { cleanExcerpt, slugFromURL, increaseImageSize, processHTMLContent } from '../lib/process.js';
4
+ describe('Utils', function () {
5
+ it('cleanExcerpt', function () {
6
+ const excerpt = cleanExcerpt('<div class="lorem" style="color: #f00;"><p><span style="font-weight: 400;">Lorem <b>Ipsum</b> <a href="https://example.com" title="Link to Dolor" style="color: blue;" rel="noreferrer" target="_blank">Dolor</a></span></div>');
7
+ assert.equal(excerpt, 'Lorem <b>Ipsum</b> <a href="https://example.com" title="Link to Dolor" rel="noreferrer" target="_blank">Dolor</a>');
8
+ });
9
+ it('slugFromURL', function () {
10
+ const slug = slugFromURL('http://example.blogspot.com/2017/06/ipsum.html');
11
+ assert.equal(slug, 'ipsum');
12
+ });
13
+ it('increaseImageSize', function () {
14
+ const image1 = increaseImageSize('https://3.bp.blogspot.com/-dQmeqRna7MA/V56ZIKQmPJI/AAAAAAAAJeU/1234_abcd3YT3BmCduGnz2tE4xrlp_c1gCLcB/s1600/photo.jpg');
15
+ const image2 = increaseImageSize('https://3.bp.blogspot.com/-dQmeqRna7MA/V56ZIKQmPJI/AAAAAAAAJeU/1234_abcd3YT3BmCduGnz2tE4xrlp_c1gCLcB/s1600-h/photo.jpg');
16
+ assert.equal(image1, 'https://3.bp.blogspot.com/-dQmeqRna7MA/V56ZIKQmPJI/AAAAAAAAJeU/1234_abcd3YT3BmCduGnz2tE4xrlp_c1gCLcB/s2000/photo.jpg');
17
+ assert.equal(image2, 'https://3.bp.blogspot.com/-dQmeqRna7MA/V56ZIKQmPJI/AAAAAAAAJeU/1234_abcd3YT3BmCduGnz2tE4xrlp_c1gCLcB/s2000/photo.jpg');
18
+ });
19
+ });
20
+ describe('Process HTML', function () {
21
+ it('Can increase image sizes', async function () {
22
+ const processed = await processHTMLContent({
23
+ postData: {},
24
+ options: {},
25
+ html: '<img src="http://1.bp.blogspot.com/_-abcdNGLDs4/abcdNoxb7NI/AAAAAAAAAaU/PA-oWpq0Iug/s1600-h/photo.jpg">'
26
+ });
27
+ assert.equal(processed.html, '<img src="http://1.bp.blogspot.com/_-abcdNGLDs4/abcdNoxb7NI/AAAAAAAAAaU/PA-oWpq0Iug/s2000/photo.jpg">');
28
+ });
29
+ it('Can change divs to paragraphs', async function () {
30
+ const processed = await processHTMLContent({
31
+ postData: {},
32
+ options: {},
33
+ html: '<div style="color: #232d32; font-family: Lato, sans-serif; font-size: 16px; line-height: 1.5; white-space: pre-line;">\nLorem ipsum dolor sit amet, consectetur adipiscing elit</div>'
34
+ });
35
+ assert.equal(processed.html, '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>');
36
+ });
37
+ it('Remove empty divs with no attributes', async function () {
38
+ const processed = await processHTMLContent({
39
+ postData: {},
40
+ options: {},
41
+ html: '<div></div><div> </div><div class="hello"></div><div class="hello"> </div>'
42
+ });
43
+ assert.equal(processed.html, '<div class="hello"></div>\n<div class="hello"> </div>');
44
+ });
45
+ it('Can remove anchors that link to direct child image', async function () {
46
+ const processed = await processHTMLContent({
47
+ postData: {},
48
+ options: {},
49
+ html: '<a href="https://3.bp.blogspot.com/my-image.jpg"><img src="https://3.bp.blogspot.com/my-image.jpg"></a>'
50
+ });
51
+ assert.equal(processed.html, '<img src="https://3.bp.blogspot.com/my-image.jpg">');
52
+ });
53
+ it('Can remove the first element if a <hr>', async function () {
54
+ const processed = await processHTMLContent({ postData: {}, options: {}, html: '<hr><p>My text</p>' });
55
+ assert.equal(processed.html, '<p>My text</p>');
56
+ });
57
+ it('Can remove the first elements if multiple <hr>', async function () {
58
+ const processed = await processHTMLContent({
59
+ postData: {},
60
+ options: {},
61
+ html: '<hr><hr><hr><p>My text</p>'
62
+ });
63
+ assert.equal(processed.html, '<p>My text</p>');
64
+ });
65
+ it('Can convert to unordered list', async function () {
66
+ const processed = await processHTMLContent({
67
+ postData: {},
68
+ options: {},
69
+ html: `<div>My text</div><li>Lorem</li><li>Ipsum</li><li>Dolor</li><div><br /></div><div>My other text</div><div><br /></div>`
70
+ });
71
+ assert.equal(processed.html, '<p>My text</p>\n<ul><li>Lorem</li><li>Ipsum</li><li>Dolor</li></ul>\n\n\n\n<p>My other text</p>');
72
+ });
73
+ it('Can unwrap linked image tables', async function () {
74
+ const processed = await processHTMLContent({
75
+ postData: {},
76
+ options: {},
77
+ html: '<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto;"><tbody><tr><td style="text-align: center;"><a href="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s1280/image.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="640" data-original-width="1280" src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s320/image.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Image caption</td></tr></tbody></table>'
78
+ });
79
+ assert.equal(processed.html, '<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s2000/image.png" class="kg-image" alt loading="lazy"><figcaption>Image caption</figcaption></figure>');
80
+ });
81
+ it('Can unwrap unlinked image tables', async function () {
82
+ const processed = await processHTMLContent({
83
+ postData: {},
84
+ options: {},
85
+ html: '<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><img border="0" data-original-height="572" data-original-width="1000" height="227" src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s320/image.png" style="margin-left: auto; margin-right: auto;" width="400" /></td></tr><tr><td class="tr-caption" style="text-align: center;"><div style="text-align: center;">Image caption</div></td></tr></tbody></table>'
86
+ });
87
+ assert.equal(processed.html, '<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s2000/image.png" class="kg-image" alt loading="lazy"><figcaption>Image caption</figcaption></figure>');
88
+ });
89
+ it('Can unwrap image tables & maintain links', async function () {
90
+ const processed = await processHTMLContent({
91
+ postData: {},
92
+ options: {},
93
+ html: '<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto;"><tbody><tr><td style="text-align: center;"><a href="https://ghost.org" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="640" data-original-width="1280" src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s320/image.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Image caption</td></tr></tbody></table>'
94
+ });
95
+ assert.equal(processed.html, '<figure class="kg-card kg-image-card kg-card-hascaption"><a href="https://ghost.org"><img src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s2000/image.png" class="kg-image" alt loading="lazy"></a><figcaption>Image caption</figcaption></figure>');
96
+ });
97
+ it('Can use first image as featured image (type 1)', async function () {
98
+ const processed = await processHTMLContent({
99
+ postData: {},
100
+ options: { firstImageAsFeatured: true },
101
+ html: `<p style="text-align: center;">&nbsp;</p><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s1000/image.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="301" src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s320/image.png" width="481" /></a></div><br /><p></p><h3 style="text-align: left;"><b>My headline</b></h3>`
102
+ });
103
+ assert.equal(processed.feature_image, 'https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s2000/image.png');
104
+ assert.equal(processed.html, '<h3>My headline</h3>');
105
+ });
106
+ it('Can use first image as featured image (type 2)', async function () {
107
+ const processed = await processHTMLContent({
108
+ postData: {},
109
+ options: { firstImageAsFeatured: true },
110
+ html: `<p style="text-align: center;"><br /></p><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s1000/image.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1200" height="382" src="https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s320/image.png" width="509" /></a></div><p></p><h2 style="text-align: left;">Headline</h2>`
111
+ });
112
+ assert.equal(processed.feature_image, 'https://1.bp.blogspot.com/-12345678Um0/abcdo6O6gMI/qwertyAABuk/1234abcdZ5w7EHoyg9jIAupZIXYLQj42gCLcBGAsYHQ/s2000/image.png');
113
+ assert.equal(processed.html, '<h2>Headline</h2>');
114
+ });
115
+ it('Leaves images without a source alone', async function () {
116
+ const processed = await processHTMLContent({ postData: {}, html: '<p>Text <img alt="x"></p>' });
117
+ assert.equal(processed.html, 'Text <img alt="x">');
118
+ });
119
+ it('Leaves caption tables without an image alone', async function () {
120
+ const processed = await processHTMLContent({
121
+ postData: {},
122
+ html: '<table class="tr-caption-container"><tbody><tr><td class="tr-caption">Only a caption</td></tr></tbody></table>'
123
+ });
124
+ assert.equal(processed.html, '<table class="tr-caption-container">\n<tbody>\n<tr>\n<td class="tr-caption">Only a caption</td>\n</tr>\n</tbody>\n</table>');
125
+ });
126
+ it('Unwraps caption tables without a caption or a link target', async function () {
127
+ const processed = await processHTMLContent({
128
+ postData: {},
129
+ html: '<table class="tr-caption-container"><tbody><tr><td><a name="x"><img src="https://1.bp.blogspot.com/a/s320/i.png"></a></td></tr></tbody></table>'
130
+ });
131
+ assert.equal(processed.html, '<figure class="kg-card kg-image-card"><img src="https://1.bp.blogspot.com/a/s2000/i.png" class="kg-image" alt loading="lazy"></figure>');
132
+ });
133
+ it('Keeps image links to other pages and Koenig cards', async function () {
134
+ const html = '<a href="https://x.com/i.jpg" class="kg-image"><img src="https://x.com/i.jpg"></a><a href="https://x.com/j.jpg"><img class="kg-image" src="https://x.com/j.jpg"></a><a href="https://ghost.org"><img src="https://x.com/k.jpg"></a>';
135
+ const processed = await processHTMLContent({ postData: {}, html });
136
+ assert.equal(processed.html, `<p>${html}</p>`);
137
+ });
138
+ it('Converts bulleted pre-formatted divs to list items', async function () {
139
+ const processed = await processHTMLContent({
140
+ postData: {},
141
+ html: '<div><span style="white-space: pre">\t</span>• One </div><div><span style="white-space: pre"> </span>Two</div><span style="white-space: pre">x</span><div> <b>a</b>•<span style="white-space: pre"> </span></div><div><b>b</b>• Three<span style="white-space: pre"> </span> <i>z</i></div>'
142
+ });
143
+ assert.equal(processed.html, '<ul><li>• One</li></ul>\n<div><span style="white-space: pre"> </span>Two</div>\n<p><span style="white-space: pre">x</span>\n</p><ul><li><b>a</b>•</li><li><b>b</b>• Three <i>z</i></li></ul>');
144
+ });
145
+ it('Trims whitespace around list item text', async function () {
146
+ const processed = await processHTMLContent({
147
+ postData: {},
148
+ html: '<div> <span style="white-space: pre">\t</span>• One<b>x</b> </div>'
149
+ });
150
+ assert.equal(processed.html, '<ul><li>• One<b>x</b></li></ul>');
151
+ });
152
+ it('Converts styled spans and centred divs to paragraphs and cleans headings', async function () {
153
+ const processed = await processHTMLContent({
154
+ postData: {},
155
+ html: '<span style="background-color: #fff; color: #000; font-family: Arial; font-size: 11pt; white-space: pre-line;">Styled</span><div style="text-align: center;">Centred</div><h2 style="text-align: left;">Left</h2><h2 style="color: red;">Red</h2><h3><b>Bold</b> heading</h3>'
156
+ });
157
+ assert.equal(processed.html, '<p><p>Styled</p>\n</p><p>Centred</p>\n<h2>Left</h2>\n<h2 style="color: red;">Red</h2>\n<h3>Bold heading</h3>');
158
+ });
159
+ it('Unwraps divs holding only an image', async function () {
160
+ const processed = await processHTMLContent({ postData: {}, html: '<div><img src="https://x.com/a.jpg"></div>' });
161
+ assert.equal(processed.html, '<img src="https://x.com/a.jpg">');
162
+ });
163
+ it('Removes non-breaking space paragraphs and keeps styled ones', async function () {
164
+ const processed = await processHTMLContent({
165
+ postData: {},
166
+ html: '<p class="x">&nbsp;</p><div>&nbsp;</div><p>&nbsp; </p><div class="a">&nbsp;</div>'
167
+ });
168
+ assert.equal(processed.html, '<p>&nbsp;</p>\n\n<div class="a">&nbsp;</div>');
169
+ });
170
+ it('Resizes YouTube embeds', async function () {
171
+ const processed = await processHTMLContent({
172
+ postData: {},
173
+ html: '<iframe src="https://www.youtube.com/embed/abc" width="560" height="315"></iframe>'
174
+ });
175
+ assert.equal(processed.html, '<p><iframe src="https://www.youtube.com/embed/abc" width="160" height="90"></iframe></p>');
176
+ });
177
+ describe('First image as featured image', function () {
178
+ const featured = (html) => processHTMLContent({ postData: {}, html, options: { firstImageAsFeatured: true } });
179
+ it('handles empty content', async function () {
180
+ assert.deepEqual(await featured(''), { html: '' });
181
+ });
182
+ it('uses a leading image', async function () {
183
+ assert.deepEqual(await featured('<img src="https://x.com/a.jpg"><p>Text</p>'), {
184
+ html: '<p>Text</p>',
185
+ feature_image: 'https://x.com/a.jpg'
186
+ });
187
+ });
188
+ it('ignores images after text', async function () {
189
+ assert.deepEqual(await featured('<p>Text first</p><img src="https://x.com/a.jpg">'), {
190
+ html: '<p>Text first</p>\n<img src="https://x.com/a.jpg">'
191
+ });
192
+ });
193
+ it('uses an unlinked image in an empty first element', async function () {
194
+ for (const html of [
195
+ '<div class="separator"><img src="https://x.com/a.jpg"></div><p>Text</p>',
196
+ '<div class="separator"><a name="x"><img src="https://x.com/a.jpg"></a></div><p>Text</p>'
197
+ ]) {
198
+ assert.deepEqual(await featured(html), { html: '<p>Text</p>', feature_image: 'https://x.com/a.jpg' });
199
+ }
200
+ });
201
+ it('uses an image linked to the same image at another size', async function () {
202
+ assert.deepEqual(await featured('<div class="separator"><a href="https://x.com/a-s1600.jpg"><img src="https://x.com/a-s320.jpg"></a></div><p>Text</p>'), { html: '<p>Text</p>', feature_image: 'https://x.com/a-s320.jpg' });
203
+ });
204
+ it('keeps an image linked elsewhere', async function () {
205
+ assert.deepEqual(await featured('<div class="separator"><a href="https://x.com/b.jpg"><img src="https://x.com/a.jpg"></a></div><p>Text</p>'), { html: '<div><a href="https://x.com/b.jpg"><img src="https://x.com/a.jpg"></a></div>\n<p>Text</p>' });
206
+ });
207
+ it('keeps a leading embed that has no image', async function () {
208
+ assert.deepEqual(await featured('<p><iframe src="https://www.youtube.com/embed/abc"></iframe></p><p>Text</p>'), {
209
+ html: '<p><iframe height="90" width="160" src="https://www.youtube.com/embed/abc"></iframe></p>\n<p>Text</p>'
210
+ });
211
+ });
212
+ });
213
+ });
214
+ //# sourceMappingURL=process.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.test.js","sourceRoot":"","sources":["../../src/test/process.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AACvC,OAA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": "Migrate content from the Blogger API to Ghost",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "git+https://github.com/TryGhost/migrate.git",
@@ -8,27 +9,41 @@
8
9
  },
9
10
  "author": "Ghost Foundation",
10
11
  "license": "MIT",
11
- "main": "index.js",
12
+ "main": "build/index.js",
12
13
  "type": "module",
14
+ "types": "./build/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./build/index.d.ts",
18
+ "default": "./build/index.js"
19
+ }
20
+ },
13
21
  "files": [
14
- "index.js",
15
- "lib"
22
+ "build"
16
23
  ],
17
24
  "publishConfig": {
18
25
  "access": "public"
19
26
  },
20
- "devDependencies": {},
27
+ "devDependencies": {
28
+ "@types/node": "24.19.2",
29
+ "c8": "12.0.0",
30
+ "nock": "15.0.6",
31
+ "typescript": "7.0.2"
32
+ },
21
33
  "dependencies": {
22
- "@tryghost/errors": "3.4.2",
23
- "@tryghost/mg-utils": "0.11.7",
24
- "@tryghost/string": "0.3.7",
34
+ "@tryghost/errors": "3.4.6",
35
+ "@tryghost/mg-context": "0.12.0-0",
36
+ "@tryghost/mg-ghost-authors": "0.11.0-0",
37
+ "@tryghost/mg-utils": "0.12.0-0",
38
+ "@tryghost/string": "0.3.8",
25
39
  "autop": "1.0.1",
26
- "node-fetch": "3.3.2",
27
- "sanitize-html": "2.18.0",
40
+ "html-entities": "2.6.0",
41
+ "sanitize-html": "2.18.1",
28
42
  "simple-dom": "1.4.0"
29
43
  },
30
44
  "scripts": {
31
- "dev": "echo \"Implement me!\"",
32
- "test": "node --test 'test/**/*.test.js'"
45
+ "build": "tsc --build",
46
+ "test": "c8 --src src --all --check-coverage --100 --exclude '**/test/**' --exclude '**/*.d.ts' node --test 'build/test/**/*.test.js'",
47
+ "test:local": "pnpm build && pnpm test"
33
48
  }
34
49
  }
package/index.js DELETED
@@ -1,7 +0,0 @@
1
- import fetch from './lib/fetch.js';
2
- import process from './lib/process.js';
3
-
4
- export default {
5
- fetch,
6
- process
7
- };
package/lib/fetch.js DELETED
@@ -1,82 +0,0 @@
1
- import errors from '@tryghost/errors';
2
- import fetch from 'node-fetch';
3
-
4
- const getSiteContent = async (apiKey, blogID, type = 'posts') => {
5
- let response = {
6
- nextPageToken: true
7
- };
8
- let results = [];
9
- let pageToken = false;
10
-
11
- do {
12
- try {
13
- const searchParams = new URLSearchParams({
14
- key: apiKey
15
- });
16
-
17
- // Wait fot 500ms to prevent rate limiting
18
- await new Promise(resolve => setTimeout(resolve, 500)); // eslint-disable-line no-promise-executor-return
19
-
20
- if (pageToken) {
21
- searchParams.set('pageToken', pageToken);
22
- }
23
-
24
- let reqUrl = `https://www.googleapis.com/blogger/v3/blogs/${blogID}/${type}?` + searchParams;
25
-
26
- let request = await fetch(reqUrl);
27
-
28
- response = await request.json();
29
- results = results.concat(response.items);
30
- pageToken = response.nextPageToken;
31
- } catch (error) {
32
- throw new errors.InternalServerError({message: 'Failed to fetch Blogger content', error});
33
- }
34
- } while (response.nextPageToken);
35
-
36
- return results;
37
- };
38
-
39
- const cachedFetch = async (fileCache, apiKey, blogID, type) => {
40
- let filename = `blogger_api_${blogID}_${type}.json`;
41
-
42
- if (fileCache.hasFile(filename, 'tmp')) {
43
- return await fileCache.readTmpJSONFile(filename);
44
- }
45
-
46
- let response = await getSiteContent(apiKey, blogID, type);
47
-
48
- await fileCache.writeTmpFile(response, filename);
49
-
50
- return response;
51
- };
52
-
53
- const tasks = async ({apiKey, blogID}, ctx) => {
54
- const tasks = []; // eslint-disable-line no-shadow
55
-
56
- ctx.result = {
57
- posts: []
58
- };
59
-
60
- blogID.forEach(singleblogID => {
61
- tasks.push({
62
- title: `Fetching posts for ${singleblogID}`,
63
- task: async ctx => {
64
- // eslint-disable-line no-shadow
65
- try {
66
- let response = await cachedFetch(ctx.fileCache, apiKey, singleblogID, 'posts');
67
-
68
- ctx.result.posts = ctx.result.posts.concat(response);
69
- } catch (error) {
70
- ctx.errors.push(error);
71
- throw error;
72
- }
73
- }
74
- });
75
- });
76
-
77
- return tasks;
78
- };
79
-
80
- export default {
81
- tasks
82
- };