contentful-export 7.14.58 → 7.16.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,11 +1,14 @@
1
1
  #!/usr/bin/env node
2
+
3
+ // eslint-disable-next-line
2
4
  const runContentfulExport = require('../dist/index')
5
+ // eslint-disable-next-line
3
6
  const usageParams = require('../dist/usageParams')
4
7
 
5
8
  console.log('We moved the CLI version of this tool into our Contentful CLI.\nThis allows our users to use and install only one single CLI tool to get the full Contentful experience.\nFor more info please visit https://github.com/contentful/contentful-cli/tree/master/docs/space/export')
6
9
 
7
10
  runContentfulExport(usageParams)
8
- .then((result) => {
11
+ .then(() => {
9
12
  process.exit(0)
10
13
  })
11
14
  .catch((err) => {
package/dist/index.js CHANGED
@@ -104,7 +104,7 @@ function runContentfulExport(params) {
104
104
  skip: ctx => !options.downloadAssets || !Object.prototype.hasOwnProperty.call(ctx.data, 'assets')
105
105
  }, {
106
106
  title: 'Write export log file',
107
- task: ctx => {
107
+ task: () => {
108
108
  return new _listr.default([{
109
109
  title: 'Lookup directory to store the logs',
110
110
  task: ctx => {
@@ -116,7 +116,7 @@ function runContentfulExport(params) {
116
116
  }
117
117
  }, {
118
118
  title: 'Create log directory',
119
- task: ctx => {
119
+ task: () => {
120
120
  return (0, _mkdirp.default)(options.exportDir);
121
121
  },
122
122
  skip: ctx => !ctx.logDirectoryExists
@@ -11,9 +11,13 @@ var _bluebird = _interopRequireDefault(require("bluebird"));
11
11
 
12
12
  var _figures = _interopRequireDefault(require("figures"));
13
13
 
14
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
14
+ var _fs = require("fs");
15
15
 
16
- var _request = _interopRequireDefault(require("request"));
16
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
17
+
18
+ var _stream = require("stream");
19
+
20
+ var _util = require("util");
17
21
 
18
22
  var _embargoedAssets = require("../utils/embargoedAssets");
19
23
 
@@ -21,38 +25,37 @@ var _getEntityName = _interopRequireDefault(require("contentful-batch-libs/dist/
21
25
 
22
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
27
 
24
- function downloadAsset({
28
+ const streamPipeline = (0, _util.promisify)(_stream.pipeline);
29
+
30
+ async function downloadAsset({
25
31
  url,
26
32
  directory
27
33
  }) {
28
- return new _bluebird.default(function (resolve, reject) {
29
- // handle urls without protocol
30
- if (url.startsWith('//')) {
31
- url = 'https:' + url;
32
- } // build local file path from the url for the download
33
-
34
+ // handle urls without protocol
35
+ if (url.startsWith('//')) {
36
+ url = 'https:' + url;
37
+ } // build local file path from the url for the download
34
38
 
35
- const parsedUrl = new URL(url);
36
39
 
37
- const localFile = _path.default.join(directory, parsedUrl.host, parsedUrl.pathname); // ensure directory exists and create file stream
40
+ const parsedUrl = new URL(url);
38
41
 
42
+ const localFile = _path.default.join(directory, parsedUrl.host, parsedUrl.pathname); // ensure directory exists and create file stream
39
43
 
40
- _fsExtra.default.mkdirsSync(_path.default.dirname(localFile));
41
44
 
42
- const file = _fsExtra.default.createWriteStream(localFile); // download asset
45
+ await _fs.promises.mkdir(_path.default.dirname(localFile), {
46
+ recursive: true
47
+ });
48
+ const file = (0, _fs.createWriteStream)(localFile); // download asset
43
49
 
50
+ const assetRequest = await (0, _nodeFetch.default)(url);
44
51
 
45
- const assetRequest = _request.default.get(url); // pipe response content to file
52
+ if (!assetRequest.ok) {
53
+ throw new Error(`error response status: ${assetRequest.status}`);
54
+ } // Wait for stream to be consumed before returning local file
46
55
 
47
56
 
48
- assetRequest.on('error', err => {
49
- reject(err);
50
- }).on('response', response => {
51
- if (response.statusCode >= 400) {
52
- reject(new Error('error response status: ' + response.statusCode));
53
- }
54
- }).pipe(file).on('finish', () => resolve(localFile));
55
- });
57
+ await streamPipeline(assetRequest.body, file);
58
+ return localFile;
56
59
  }
57
60
 
58
61
  function downloadAssets(options) {
@@ -47,7 +47,7 @@ function getFullSourceSpace({
47
47
  };
48
48
  return new _listr.default([{
49
49
  title: 'Connecting to space',
50
- task: (0, _listr2.wrapTask)((ctx, task) => {
50
+ task: (0, _listr2.wrapTask)(ctx => {
51
51
  return client.getSpace(spaceId).then(space => {
52
52
  ctx.space = space;
53
53
  return space.getEnvironment(environmentId);
@@ -57,7 +57,7 @@ function getFullSourceSpace({
57
57
  })
58
58
  }, {
59
59
  title: 'Fetching content types data',
60
- task: (0, _listr2.wrapTask)((ctx, task) => {
60
+ task: (0, _listr2.wrapTask)(ctx => {
61
61
  return pagedGet({
62
62
  source: ctx.environment,
63
63
  method: 'getContentTypes'
@@ -68,20 +68,20 @@ function getFullSourceSpace({
68
68
  skip: () => skipContentModel
69
69
  }, {
70
70
  title: 'Fetching tags data',
71
- task: (0, _listr2.wrapTask)((ctx, task) => {
71
+ task: (0, _listr2.wrapTask)(ctx => {
72
72
  return pagedGet({
73
73
  source: ctx.environment,
74
74
  method: 'getTags'
75
75
  }).then(extractItems).then(items => {
76
76
  ctx.data.tags = items;
77
- }).catch(e => {
77
+ }).catch(() => {
78
78
  ctx.data.tags = [];
79
79
  });
80
80
  }),
81
81
  skip: () => cdaClient
82
82
  }, {
83
83
  title: 'Fetching editor interfaces data',
84
- task: (0, _listr2.wrapTask)((ctx, task) => {
84
+ task: (0, _listr2.wrapTask)(ctx => {
85
85
  return getEditorInterfaces(ctx.data.contentTypes).then(editorInterfaces => {
86
86
  ctx.data.editorInterfaces = editorInterfaces.filter(editorInterface => {
87
87
  return editorInterface !== null;
@@ -91,7 +91,7 @@ function getFullSourceSpace({
91
91
  skip: ctx => skipContentModel || skipEditorInterfaces || ctx.data.contentTypes.length === 0 && 'Skipped since no content types downloaded'
92
92
  }, {
93
93
  title: 'Fetching content entries data',
94
- task: (0, _listr2.wrapTask)((ctx, task) => {
94
+ task: (0, _listr2.wrapTask)(ctx => {
95
95
  const source = cdaClient || ctx.environment;
96
96
 
97
97
  if (cdaClient) {
@@ -112,7 +112,7 @@ function getFullSourceSpace({
112
112
  skip: () => skipContent
113
113
  }, {
114
114
  title: 'Fetching assets data',
115
- task: (0, _listr2.wrapTask)((ctx, task) => {
115
+ task: (0, _listr2.wrapTask)(ctx => {
116
116
  const source = cdaClient || ctx.environment;
117
117
  queryAssets = queryAssets || {};
118
118
  queryAssets.locale = '*';
@@ -127,7 +127,7 @@ function getFullSourceSpace({
127
127
  skip: () => skipContent
128
128
  }, {
129
129
  title: 'Fetching locales data',
130
- task: (0, _listr2.wrapTask)((ctx, task) => {
130
+ task: (0, _listr2.wrapTask)(ctx => {
131
131
  return pagedGet({
132
132
  source: ctx.environment,
133
133
  method: 'getLocales'
@@ -138,7 +138,7 @@ function getFullSourceSpace({
138
138
  skip: () => skipContentModel
139
139
  }, {
140
140
  title: 'Fetching webhooks data',
141
- task: (0, _listr2.wrapTask)((ctx, task) => {
141
+ task: (0, _listr2.wrapTask)(ctx => {
142
142
  return pagedGet({
143
143
  source: ctx.space,
144
144
  method: 'getWebhooks'
@@ -149,7 +149,7 @@ function getFullSourceSpace({
149
149
  skip: () => skipWebhooks || environmentId !== 'master' && 'Webhooks can only be exported from master environment'
150
150
  }, {
151
151
  title: 'Fetching roles data',
152
- task: (0, _listr2.wrapTask)((ctx, task) => {
152
+ task: (0, _listr2.wrapTask)(ctx => {
153
153
  return pagedGet({
154
154
  source: ctx.space,
155
155
  method: 'getRoles'
@@ -162,7 +162,7 @@ function getFullSourceSpace({
162
162
  }
163
163
 
164
164
  function getEditorInterfaces(contentTypes) {
165
- return _bluebird.default.map(contentTypes, (contentType, index, length) => {
165
+ return _bluebird.default.map(contentTypes, contentType => {
166
166
  return contentType.getEditorInterface().then(editorInterface => {
167
167
  _logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
168
168
 
@@ -5,11 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- const yargs = require('yargs');
8
+ var _yargs = _interopRequireDefault(require("yargs"));
9
9
 
10
- const packageFile = require('../package');
10
+ var _package = _interopRequireDefault(require("../package"));
11
11
 
12
- var _default = yargs.version(packageFile.version || 'Version only available on installed package').usage('Usage: $0 [options]').option('space-id', {
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ var _default = _yargs.default.version(_package.default.version || 'Version only available on installed package').usage('Usage: $0 [options]').option('space-id', {
13
15
  describe: 'ID of Space with source data',
14
16
  type: 'string',
15
17
  demand: true
@@ -98,5 +100,6 @@ var _default = yargs.version(packageFile.version || 'Version only available on i
98
100
  type: 'string',
99
101
  describe: 'Pass an additional HTTP Header'
100
102
  }).config('config', 'An optional configuration JSON file containing all the options for a single run').argv;
103
+
101
104
  exports.default = _default;
102
105
  module.exports = exports.default;
@@ -7,32 +7,30 @@ exports.calculateExpiryTimestamp = calculateExpiryTimestamp;
7
7
  exports.isEmbargoedAsset = isEmbargoedAsset;
8
8
  exports.signUrl = signUrl;
9
9
 
10
- var _requestPromise = _interopRequireDefault(require("request-promise"));
11
-
12
10
  var _jsonwebtoken = _interopRequireDefault(require("jsonwebtoken"));
13
11
 
12
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
13
+
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  const SIX_HOURS_IN_MS = 6 * 60 * 60 * 1000;
17
17
  const assetKeyCache = new Map();
18
18
 
19
19
  function createAssetKey(host, accessToken, spaceId, environmentId, expiresAtMs) {
20
- const options = {
20
+ return (0, _nodeFetch.default)(`https://${host}/spaces/${spaceId}/environments/${environmentId}/asset_keys`, {
21
21
  method: 'POST',
22
- uri: `https://${host}/spaces/${spaceId}/environments/${environmentId}/asset_keys`,
23
- body: {
22
+ body: JSON.stringify({
24
23
  expiresAt: Math.floor(expiresAtMs / 1000) // in seconds
25
24
 
26
- },
25
+ }),
27
26
  headers: {
28
- Authorization: `Bearer ${accessToken}`
29
- },
30
- json: true
31
- };
32
- return (0, _requestPromise.default)(options);
27
+ Authorization: `Bearer ${accessToken}`,
28
+ 'Content-Type': 'application/json'
29
+ }
30
+ });
33
31
  }
34
32
 
35
- function createCachedAssetKey(host, accessToken, spaceId, environmentId, minExpiresAtMs) {
33
+ async function createCachedAssetKey(host, accessToken, spaceId, environmentId, minExpiresAtMs) {
36
34
  const cacheKey = `${host}:${spaceId}:${environmentId}`;
37
35
  let cacheItem = assetKeyCache.get(cacheKey);
38
36
 
@@ -43,7 +41,14 @@ function createCachedAssetKey(host, accessToken, spaceId, environmentId, minExpi
43
41
  throw new Error(`Cannot fetch an asset key so far in the future: ${minExpiresAtMs} > ${expiresAtMs}`);
44
42
  }
45
43
 
46
- const promise = createAssetKey(host, accessToken, spaceId, environmentId, expiresAtMs).catch(err => {
44
+ try {
45
+ const assetKeyPromise = createAssetKey(host, accessToken, spaceId, environmentId, expiresAtMs);
46
+ cacheItem = {
47
+ expiresAtMs,
48
+ promise: assetKeyPromise
49
+ };
50
+ assetKeyCache.set(cacheKey, cacheItem);
51
+ } catch (err) {
47
52
  // If we encounter an error, make sure to clear the cache item if this is the most recent fetch.
48
53
  const curCacheItem = assetKeyCache.get(cacheKey);
49
54
 
@@ -52,15 +57,12 @@ function createCachedAssetKey(host, accessToken, spaceId, environmentId, minExpi
52
57
  }
53
58
 
54
59
  return Promise.reject(err);
55
- });
56
- cacheItem = {
57
- expiresAtMs,
58
- promise
59
- };
60
- assetKeyCache.set(cacheKey, cacheItem);
61
- }
60
+ }
61
+ } // cacheItem.promise is the return type of node-fetch.
62
+
62
63
 
63
- return cacheItem.promise;
64
+ const response = await cacheItem.promise;
65
+ return response.json();
64
66
  }
65
67
 
66
68
  function generateSignedToken(secret, urlWithoutQueryParams, expiresAtMs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentful-export",
3
- "version": "7.14.58",
3
+ "version": "7.16.0",
4
4
  "description": "this tool allows you to export a space to a JSON dump",
5
5
  "main": "dist/index.js",
6
6
  "types": "types.d.ts",
@@ -14,7 +14,7 @@
14
14
  "build": "npm run clean && babel lib --out-dir dist",
15
15
  "build:watch": "babel lib --out-dir dist --watch",
16
16
  "clean": "rimraf dist && rimraf coverage",
17
- "lint": "eslint lib bin/*",
17
+ "lint": "eslint lib bin/* types.d.ts",
18
18
  "pretest": "npm run lint && npm run build && rimraf ./test/integration/tmp",
19
19
  "test": "npm run test:unit && npm run test:integration",
20
20
  "test:unit": "jest --testPathPattern=test/unit --coverage",
@@ -50,7 +50,6 @@
50
50
  "contentful-batch-libs": "^9.2.1",
51
51
  "contentful-management": "^10.0.0",
52
52
  "figures": "^3.2.0",
53
- "fs-extra": "^10.0.0",
54
53
  "jsonwebtoken": "^8.5.1",
55
54
  "listr": "^0.14.1",
56
55
  "listr-update-renderer": "^0.5.0",
@@ -58,8 +57,7 @@
58
57
  "lodash": "^4.17.10",
59
58
  "mkdirp": "^1.0.3",
60
59
  "moment": "^2.22.2",
61
- "request": "^2.87.0",
62
- "request-promise": "^4.2.6",
60
+ "node-fetch": "^2.6.7",
63
61
  "yargs": "^17.1.1"
64
62
  },
65
63
  "devDependencies": {
@@ -70,7 +68,7 @@
70
68
  "@babel/template": "^7.0.0",
71
69
  "@babel/types": "^7.0.0",
72
70
  "@types/jest": "^27.0.2",
73
- "babel-eslint": "^10.1.0",
71
+ "@typescript-eslint/eslint-plugin": "^5.22.0",
74
72
  "babel-jest": "^28.0.0",
75
73
  "babel-plugin-add-module-exports": "^1.0.2",
76
74
  "cz-conventional-changelog": "^3.3.0",
package/types.d.ts CHANGED
@@ -28,10 +28,9 @@ export interface Options {
28
28
  skipRoles?: boolean;
29
29
  skipWebhooks?: boolean;
30
30
  useVerboseRenderer?: boolean;
31
- };
32
-
31
+ }
33
32
 
34
33
  type ContentfulExportField = 'contentTypes' | 'entries' | 'assets' | 'locales' | 'tags' | 'webhooks' | 'roles' | 'editorInterfaces';
35
34
 
36
- declare const runContentfulExport: (params: Options) => Promise<Record<ContentfulExportField, unknown[]>>;
37
- export default runContentfulExport;
35
+ declare const runContentfulExport: (params: Options) => Promise<Record<ContentfulExportField, unknown[]>>
36
+ export default runContentfulExport