contentful-import 9.0.17 → 9.0.19

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.
@@ -24,30 +24,60 @@ async function getAssetStreamForURL(url, assetsDirectory) {
24
24
  throw error;
25
25
  }
26
26
  }
27
+ async function processAssetForLocale(locale, asset, processingOptions) {
28
+ try {
29
+ return await asset.processForLocale(locale, processingOptions);
30
+ } catch (err) {
31
+ err.entity = asset;
32
+ _logging.logEmitter.emit('error', err);
33
+ throw err;
34
+ }
35
+ }
36
+
37
+ // From
38
+ // https://stackoverflow.com/questions/67339630/how-to-get-last-resolved-promise-from-a-list-of-resolved-promises-in-javascript
39
+ async function lastResult(promises) {
40
+ if (!promises.length) throw new RangeError('No last result from no promises');
41
+ const results = [];
42
+ await Promise.all(promises.map(p => p.then(v => {
43
+ results.push(v);
44
+ })));
45
+ return results[results.length - 1];
46
+ }
27
47
  async function processAssets({
28
48
  assets,
29
49
  timeout,
30
50
  retryLimit,
31
51
  requestQueue
32
52
  }) {
33
- const pendingProcessingAssets = assets.map(asset => {
34
- return requestQueue.add(async () => {
35
- _logging.logEmitter.emit('info', `Processing Asset ${(0, _getEntityName.default)(asset)}`);
36
- const processingOptions = Object.assign({}, timeout && {
37
- processingCheckWait: timeout
38
- }, retryLimit && {
39
- processingCheckRetry: retryLimit
40
- });
41
- try {
42
- const processedAsset = await asset.processForAllLocales(processingOptions);
43
- return processedAsset;
44
- } catch (err) {
45
- err.entity = asset;
46
- _logging.logEmitter.emit('error', err);
47
- return null;
48
- }
49
- });
53
+ const processingOptions = Object.assign({}, timeout && {
54
+ processingCheckWait: timeout
55
+ }, retryLimit && {
56
+ processingCheckRetry: retryLimit
57
+ });
58
+ const pendingProcessingAssets = assets.map(async asset => {
59
+ _logging.logEmitter.emit('info', `Processing Asset ${(0, _getEntityName.default)(asset)}`);
60
+
61
+ // We want to do what processForAllLocale does, but as the rate
62
+ // limit is only enforced if we have a dedicated requestQueue item
63
+ // for every processForLocale call, we need to duplicate the logic
64
+ // here
65
+ const locales = Object.keys(asset.fields.file || {});
66
+ let latestAssetVersion = asset;
67
+ try {
68
+ // The last resolved promise will return the most up to date asset
69
+ // version which we need for next import steps (e.g. publishing)
70
+ latestAssetVersion = await lastResult(locales.map(locale => {
71
+ return requestQueue.add(() => processAssetForLocale(locale, asset, processingOptions));
72
+ }));
73
+ } catch (err) {
74
+ // Handle any error that arises during the processing of any locale
75
+ return null;
76
+ }
77
+ return latestAssetVersion;
50
78
  });
51
79
  const potentiallyProcessedAssets = await Promise.all(pendingProcessingAssets);
80
+
81
+ // This filters out all process attempts which failed
52
82
  return potentiallyProcessedAssets.filter(asset => asset);
53
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentful-import",
3
- "version": "9.0.17",
3
+ "version": "9.0.19",
4
4
  "description": "this tool allows you to import JSON dump exported by contentful-export",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -55,7 +55,7 @@
55
55
  "bluebird": "^3.5.1",
56
56
  "cli-table3": "^0.6.0",
57
57
  "contentful-batch-libs": "^9.5.0",
58
- "contentful-management": "^10.45.1",
58
+ "contentful-management": "^10.46.0",
59
59
  "date-fns": "^2.30.0",
60
60
  "eslint": "^8.49.0",
61
61
  "eslint-config-standard": "^17.1.0",
@@ -69,9 +69,9 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@babel/cli": "^7.22.15",
72
- "@babel/core": "^7.22.19",
72
+ "@babel/core": "^7.22.20",
73
73
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
74
- "@babel/preset-env": "^7.22.15",
74
+ "@babel/preset-env": "^7.22.20",
75
75
  "babel-jest": "^29.7.0",
76
76
  "babel-plugin-add-module-exports": "^1.0.2",
77
77
  "babel-preset-env": "^1.7.0",