Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contentful-batch-libs

Package Overview
Dependencies
Maintainers
4
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-batch-libs - npm Package Compare versions

Comparing version 6.0.4 to 7.0.0

dist/push/deletion.js

68

dist/get/get-full-source-space.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.default = undefined;
exports.default = getFullSourceSpace;

@@ -21,4 +21,2 @@ var _bluebird = require('bluebird');

var _logging = require('../utils/logging');
var _sortEntries = require('../utils/sort-entries');

@@ -32,3 +30,2 @@

var pageLimit = MAX_ALLOWED_LIMIT;
/**

@@ -57,7 +54,14 @@ * Gets all the content from a space via the management API. This includes

title: 'Connecting to space',
task: function task(ctx, _task) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task);
task: function task(ctx) {
return managementClient.getSpace(spaceId).then(function (space) {
ctx.space = space;
teardownTaskListeners();
}).catch(function (err) {
console.error(`
The destination space was not found. This can happen for multiple reasons:
- If you haven't yet, you should create your space manually.
- If your destination space is in another organization, and your user from the source space does not have access to it, you'll need to specify separate sourceManagementToken and destinationManagementToken
Full error details below.
`);
throw err;
});

@@ -67,7 +71,5 @@ }

title: 'Fetching content types data',
task: function task(ctx, _task2) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task2);
task: function task(ctx) {
return pagedGet(ctx.space, 'getContentTypes').then(extractItems).then(function (items) {
ctx.data.contentTypes = items;
teardownTaskListeners();
});

@@ -80,4 +82,3 @@ },

title: 'Fetching editor interfaces data',
task: function task(ctx, _task3) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task3);
task: function task(ctx) {
return getEditorInterfaces(ctx.data.contentTypes).then(function (editorInterfaces) {

@@ -87,3 +88,2 @@ ctx.data.editorInterfaces = editorInterfaces.filter(function (editorInterface) {

});
teardownTaskListeners();
});

@@ -96,4 +96,3 @@ },

title: 'Fetching content entries data',
task: function task(ctx, _task4) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task4);
task: function task(ctx) {
return pagedGet(ctx.space, 'getEntries').then(extractItems).then(_sortEntries2.default).then(function (items) {

@@ -103,3 +102,2 @@ return filterDrafts(items, includeDrafts);

ctx.data.entries = items;
teardownTaskListeners();
});

@@ -112,7 +110,5 @@ },

title: 'Fetching assets data',
task: function task(ctx, _task5) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task5);
task: function task(ctx) {
return pagedGet(ctx.space, 'getAssets').then(extractItems).then(function (items) {
ctx.data.assets = items;
teardownTaskListeners();
});

@@ -125,7 +121,5 @@ },

title: 'Fetching locales data',
task: function task(ctx, _task6) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task6);
task: function task(ctx) {
return pagedGet(ctx.space, 'getLocales').then(extractItems).then(function (items) {
ctx.data.locales = items;
teardownTaskListeners();
});

@@ -138,7 +132,5 @@ },

title: 'Fetching webhooks data',
task: function task(ctx, _task7) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task7);
task: function task(ctx) {
return pagedGet(ctx.space, 'getWebhooks').then(extractItems).then(function (items) {
ctx.data.webhooks = items;
teardownTaskListeners();
});

@@ -151,7 +143,5 @@ },

title: 'Fetching roles data',
task: function task(ctx, _task8) {
var teardownTaskListeners = (0, _logging.logToTaskOutput)(_task8);
task: function task(ctx) {
return pagedGet(ctx.space, 'getRoles').then(extractItems).then(function (items) {
ctx.data.roles = items;
teardownTaskListeners();
});

@@ -164,18 +154,11 @@ },

}
exports.default = getFullSourceSpace;
function getEditorInterfaces(contentTypes) {
return _bluebird2.default.map(contentTypes, function (contentType, index, length) {
return contentType.getEditorInterface().then(function (editorInterface) {
_logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
return editorInterface;
}).catch(function () {
// old contentTypes may not have an editor interface but we'll handle in a later stage
// but it should not stop getting the data process
_logging.logEmitter.emit('warning', `No editor interface found for ${contentType}`);
var editorInterfacePromises = contentTypes.map(function (contentType) {
// old contentTypes may not have an editor interface but we'll handle in a later stage
// but it should not stop getting the data process
return contentType.getEditorInterface().catch(function () {
return _bluebird2.default.resolve(null);
});
}, {
concurrency: 6
});
return _bluebird2.default.all(editorInterfacePromises);
}

@@ -195,3 +178,3 @@

limit: pageLimit,
order: 'sys.createdAt'
order: 'sys.createdAt,sys.id'
}).then(function (response) {

@@ -203,5 +186,2 @@ if (!aggregatedResponse) {

}
var page = Math.ceil(skip / pageLimit) + 1;
var pages = Math.ceil(response.total / pageLimit);
_logging.logEmitter.emit('info', `Fetched page ${page} of ${pages}`);
if (skip + pageLimit <= response.total) {

@@ -208,0 +188,0 @@ return pagedGet(space, method, skip + pageLimit, aggregatedResponse);

@@ -12,2 +12,6 @@ 'use strict';

var _npmlog = require('npmlog');
var _npmlog2 = _interopRequireDefault(_npmlog);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -28,19 +32,56 @@

spaceId = _ref.spaceId,
_ref$entryIds = _ref.entryIds,
entryIds = _ref$entryIds === undefined ? [] : _ref$entryIds,
_ref$assetIds = _ref.assetIds,
assetIds = _ref$assetIds === undefined ? [] : _ref$assetIds,
_ref$webhookIds = _ref.webhookIds,
webhookIds = _ref$webhookIds === undefined ? [] : _ref$webhookIds,
skipContentModel = _ref.skipContentModel,
skipContent = _ref.skipContent;
sourceResponse = _ref.sourceResponse,
contentModelOnly = _ref.contentModelOnly,
skipLocales = _ref.skipLocales,
skipContentModel = _ref.skipContentModel;
_npmlog2.default.info('Checking if destination space already has any content and retrieving it');
return managementClient.getSpace(spaceId).then(function (space) {
return _bluebird2.default.props({
contentTypes: skipContentModel ? _bluebird2.default.resolve([]) : space.getContentTypes().then(extractItems),
entries: skipContent ? _bluebird2.default.resolve([]) : batchedIdQuery(space, 'getEntries', entryIds),
assets: skipContent ? _bluebird2.default.resolve([]) : batchedIdQuery(space, 'getAssets', assetIds),
locales: skipContentModel ? _bluebird2.default.resolve([]) : space.getLocales().then(extractItems),
webhooks: []
var result = {};
var sourceContent = {
contentTypes: sourceResponse.contentTypes || [],
locales: sourceResponse.locales || [],
entries: sourceResponse.entries || [],
assets: sourceResponse.assets || []
};
if (!skipContentModel) {
var contentTypeIds = sourceContent.contentTypes.map(function (e) {
return e.sys.id;
});
result.contentTypes = batchedIdQuery(space, 'getContentTypes', contentTypeIds);
if (!skipLocales) {
var localeIds = sourceContent.locales.map(function (e) {
return e.sys.id;
});
result.locales = batchedIdQuery(space, 'getLocales', localeIds);
}
}
if (contentModelOnly) {
return _bluebird2.default.props(result);
}
var entryIds = sourceContent.entries.map(function (e) {
return e.sys.id;
});
var assetIds = sourceContent.assets.map(function (e) {
return e.sys.id;
});
result.entries = batchedIdQuery(space, 'getEntries', entryIds);
result.assets = batchedIdQuery(space, 'getAssets', assetIds);
result.webhooks = [];
return _bluebird2.default.props(result);
}, function (err) {
_npmlog2.default.error(`
The destination space was not found. This can happen for multiple reasons:
- If you haven't yet, you should create your space manually.
- If your destination space is in another organization, and your user from the source space does not have access to it, you'll need to specify separate sourceManagementToken and destinationManagementToken
Full error details below.
`);
throw err;
});

@@ -61,6 +102,2 @@ }

function extractItems(response) {
return response.items;
}
function getIdBatches(ids) {

@@ -67,0 +104,0 @@ var batches = [];

@@ -12,8 +12,10 @@ 'use strict';

var _getEntityName = require('../utils/get-entity-name');
var _npmlog = require('npmlog');
var _npmlog2 = _interopRequireDefault(_npmlog);
var _getEntityName = require('./get-entity-name');
var _getEntityName2 = _interopRequireDefault(_getEntityName);
var _logging = require('../utils/logging');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,6 +25,5 @@

return _bluebird2.default.map(assets, function (asset) {
_logging.logEmitter.emit('info', `Processing Asset ${(0, _getEntityName2.default)(asset)}`);
return asset.processForAllLocales().catch(function (err) {
err.entity = asset;
_logging.logEmitter.emit('error', err);
_npmlog2.default.info(`Processing Asset ${(0, _getEntityName2.default)(asset)}`);
return asset.processForAllLocales().catch(function () {
_npmlog2.default.info('Error Processing this asset, continuing...');
return _bluebird2.default.resolve(null);

@@ -29,0 +30,0 @@ });

@@ -16,2 +16,6 @@ 'use strict';

var _npmlog = require('npmlog');
var _npmlog2 = _interopRequireDefault(_npmlog);
var _function = require('lodash/function');

@@ -23,8 +27,10 @@

var _getEntityName = require('../utils/get-entity-name');
var _getEntityName = require('./get-entity-name');
var _getEntityName2 = _interopRequireDefault(_getEntityName);
var _logging = require('../utils/logging');
var _errorBuffer = require('../utils/error-buffer');
var _errorBuffer2 = _interopRequireDefault(_errorBuffer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -43,7 +49,3 @@

return promise.then((0, _function.partial)(creationSuccessNotifier, operation)).catch((0, _function.partial)(handleCreationErrors, entity));
}, { concurrency: 6 }).then(function (entries) {
return entries.filter(function (entry) {
return entry;
});
});
}, { concurrency: 6 });
}

@@ -103,7 +105,13 @@

}
err.entity = entity.original;
_logging.logEmitter.emit('error', err);
// No need to pass this entity down to publishing if it wasn't created
return null;
if ((0, _object.get)(err, 'error.sys.id') === 'VersionMismatch') {
_npmlog2.default.error('Content update error:');
_npmlog2.default.error('Error', err.error);
_npmlog2.default.error('Request', err.request);
_npmlog2.default.error(`
This probably means you are synchronizing over a space with previously existing
content, or that you don't have the sync token for the last sync you performed
to this space.
`);
}
throw err;
}

@@ -125,5 +133,3 @@

err.contentModelWasSkipped = skipContentModel;
err.entity = entry.original;
_logging.logEmitter.emit('error', err);
_errorBuffer2.default.push(err);
// No need to pass this entry down to publishing if it wasn't created

@@ -152,3 +158,3 @@ return null;

var verb = method[0].toUpperCase() + method.substr(1, method.length) + 'd';
_logging.logEmitter.emit('info', `${verb} ${createdEntity.sys.type} ${(0, _getEntityName2.default)(createdEntity)}`);
_npmlog2.default.info(`${verb} ${createdEntity.sys.type} ${(0, _getEntityName2.default)(createdEntity)}`);
return createdEntity;

@@ -155,0 +161,0 @@ }

@@ -6,4 +6,13 @@ 'use strict';

});
exports.pushToSpace = exports.publishing = exports.creation = exports.assets = undefined;
exports.pushToSpace = exports.getEntityName = exports.publishing = exports.deletion = exports.creation = exports.assets = undefined;
var _getEntityName = require('./get-entity-name');
Object.defineProperty(exports, 'getEntityName', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_getEntityName).default;
}
});
var _pushToSpace = require('./push-to-space');

@@ -26,2 +35,6 @@

var _deletion = require('./deletion');
var deletion = _interopRequireWildcard(_deletion);
var _publishing = require('./publishing');

@@ -37,2 +50,3 @@

exports.creation = creation;
exports.deletion = deletion;
exports.publishing = publishing;

@@ -7,2 +7,3 @@ 'use strict';

exports.publishEntities = publishEntities;
exports.unpublishEntities = unpublishEntities;

@@ -13,12 +14,16 @@ var _bluebird = require('bluebird');

var _getEntityName = require('../utils/get-entity-name');
var _npmlog = require('npmlog');
var _npmlog2 = _interopRequireDefault(_npmlog);
var _getEntityName = require('./get-entity-name');
var _getEntityName2 = _interopRequireDefault(_getEntityName);
var _logging = require('../utils/logging');
var _errorBuffer = require('../utils/error-buffer');
var _errorBuffer2 = _interopRequireDefault(_errorBuffer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/**

@@ -30,5 +35,14 @@ * Publish a list of entities.

function publishEntities(entities) {
if (entities.length === 0) {
_npmlog2.default.info(`Skip publishing since zero entities passed`);
return entities;
}
var entity = entities[0].original || entities[0];
var type = entity.sys.type || 'unknown type';
_npmlog2.default.info(`Publishing ${entities.length} ${type}s`);
var entitiesToPublish = entities.filter(function (entity) {
if (!entity || !entity.publish) {
_logging.logEmitter.emit('warning', `Unable to publish ${(0, _getEntityName2.default)(entity)}`);
_npmlog2.default.info('Error while publishing entity: Unable to parse entity');
_npmlog2.default.info(`Unparseable entity: ${JSON.stringify(entity, null, 0)}`);
return false;

@@ -39,13 +53,15 @@ }

if (entitiesToPublish.length === 0) {
_logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
return _bluebird2.default.resolve([]);
}
var entity = entities[0].original || entities[0];
var type = entity.sys.type || 'unknown type';
_logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
return runQueue(entitiesToPublish).then(function (result) {
_logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
return _bluebird2.default.map(entitiesToPublish, function (entity, index) {
return entity.publish().then(function (entity) {
_npmlog2.default.info(`Published ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
return entity;
}, function (err) {
_errorBuffer2.default.push(err);
_npmlog2.default.info(`Failed to publish ${entity.sys.id} (${(0, _getEntityName2.default)(entity)})`);
return null;
}).then(function (entity) {
return _bluebird2.default.delay(500, entity);
});
}, { concurrency: 1 }).then(function (result) {
_npmlog2.default.info(`Finished publishing ${entities.length} ${type}s. Returning ${result.length} entities`);
return result;

@@ -55,41 +71,21 @@ });

function runQueue(queue, result) {
if (!result) {
result = [];
}
return _bluebird2.default.map(queue, function (entity, index) {
_logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
return entity.publish().then(function (entity) {
/**
* Unpublish a list of entities.
* Returns a reject promise if unpublishing fails.
*/
function unpublishEntities(entities) {
return _bluebird2.default.map(entities, function (entity, index) {
if (!entity || !entity.unpublish) {
_npmlog2.default.info('Error While Unpublishing: entity undefined entity at index ' + index);
return _bluebird2.default.resolve(entity);
}
return entity.unpublish().then(function (entity) {
_npmlog2.default.info(`Unpublished ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
return entity;
}, function (err) {
_logging.logEmitter.emit('error', err);
return null;
// In case the entry has already been unpublished
if (err.name === 'BadRequest') return entity;
throw err;
});
}, { concurrency: 1 }).then(function (entities) {
return entities.filter(function (entity) {
return entity;
});
}).then(function (publishedEntities) {
result = [].concat(_toConsumableArray(result), _toConsumableArray(publishedEntities));
var publishedEntityIds = publishedEntities.map(function (entitiy) {
return entitiy.sys.id;
});
var unpublishedEntities = queue.filter(function (entity) {
return !publishedEntityIds.includes(entity.sys.id);
});
return unpublishedEntities;
}).then(function (unpublishedEntities) {
if (unpublishedEntities.length > 0) {
if (queue.length === unpublishedEntities.length) {
// Fail when queue could not publish at least one item
var unpublishedEntityNames = unpublishedEntities.map(_getEntityName2.default).join(', ');
_logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
} else {
// Rerun queue with unpublished entities
return runQueue(unpublishedEntities, result);
}
}
// Return only published entities + last result
return result;
});
}

@@ -31,3 +31,3 @@ 'use strict';

_logging.logEmitter.emit('info', 'Pushing content to destination space');
_npmlog2.default.info('Pushing content to destination space');

@@ -143,2 +143,6 @@ return managementClient.getSpace(spaceId).then(function (space) {

var _npmlog = require('npmlog');
var _npmlog2 = _interopRequireDefault(_npmlog);
var _assets = require('./assets');

@@ -156,4 +160,2 @@

var _logging = require('../utils/logging');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -168,2 +170,6 @@

locales: [],
deletedEntries: [],
deletedAssets: [],
deletedContentTypes: [],
deletedLocales: [],
webhooks: [],

@@ -170,0 +176,0 @@ editorInterfaces: []

@@ -16,10 +16,4 @@ 'use strict';

var _logging = require('./logging');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function logHandler(level, data) {
_logging.logEmitter.emit(level, data);
}
/**

@@ -55,4 +49,3 @@ * Generates object with delivery and management clients for both

application: opts.deliveryApplication,
integration: opts.deliveryIntegration,
logHandler
integration: opts.deliveryIntegration
});

@@ -71,6 +64,4 @@ }

httpsAgent: opts.httpsAgent,
timeout: 10000,
application: opts.managementApplication,
integration: opts.managementIntegration,
logHandler
integration: opts.managementIntegration
});

@@ -91,6 +82,4 @@ }

httpsAgent: opts.httpsAgent,
timeout: 10000,
application: opts.managementApplication,
integration: opts.managementIntegration,
logHandler
integration: opts.managementIntegration
})

@@ -97,0 +86,0 @@ };

@@ -16,20 +16,11 @@ 'use strict';

var _getEntityName = require('./get-entity-name');
var _errorBuffer = require('./error-buffer');
Object.defineProperty(exports, 'getEntityName', {
Object.defineProperty(exports, 'errorBuffer', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_getEntityName).default;
return _interopRequireDefault(_errorBuffer).default;
}
});
var _logging = require('./logging');
Object.defineProperty(exports, 'logging', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_logging).default;
}
});
var _sortEntries = require('./sort-entries');

@@ -36,0 +27,0 @@

@@ -28,3 +28,6 @@ 'use strict';

var mergedLinkedEntries = mergeSort(linkedEntries, function (a) {
return hasLinkedIndexesInFront(a);
var hli = hasLinkedIndexesInFront(a);
if (!hasLinkedIndexes(a)) return -1;
if (hli) return 1;
if (!hli) return -1;
});

@@ -40,5 +43,4 @@

return index > item.index;
}) ? 1 : -1;
});
}
return 0;
}

@@ -45,0 +47,0 @@

{
"name": "contentful-batch-libs",
"version": "6.0.4",
"version": "7.0.0",
"description": "Library modules used by contentful batch utility CLI tools.",

@@ -32,11 +32,9 @@ "main": "dist/index.js",

"dependencies": {
"bfj-node4": "4.1.0",
"bluebird": "^3.3.3",
"contentful": "^4.5.0",
"contentful-management": "^3.9.1",
"figures": "^2.0.0",
"listr": "^0.12.0",
"contentful": "^4.3.0",
"contentful-management": "^3.7.6",
"listr": "^0.11.0",
"listr-verbose-renderer": "^0.4.0",
"lodash": "^4.0.1",
"moment": "^2.18.1"
"npmlog": "^4.0.2"
},

@@ -49,14 +47,12 @@ "devDependencies": {

"babel-plugin-rewire": "^1.1.0",
"babel-preset-env": "1.6.0",
"babel-preset-env": "^1.5.2",
"babel-template": "^6.25.0",
"babel-types": "^6.25.0",
"coveralls": "2.13.1",
"coveralls": "^2.11.8",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^4.2.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.0",
"eslint": "^3.18.0",
"eslint-config-standard": "^7.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"husky": "0.14.3",
"eslint-plugin-standard": "^2.1.1",
"husky": "^0.13.2",
"in-publish": "^2.0.0",

@@ -69,4 +65,4 @@ "istanbul": "^1.0.0-alpha.2",

"semantic-release": "^6.3.2",
"sinon": "2.3.7",
"tape": "4.7.0",
"sinon": "^2.1.0",
"tape": "^4.5.1",
"trevor": "^2.3.0"

@@ -73,0 +69,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc