Socket
Socket
Sign inDemoInstall

contentful-management

Package Overview
Dependencies
Maintainers
3
Versions
578
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-management - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

rate-limit.js

40

example/clone-space.js

@@ -35,3 +35,7 @@ #!/usr/bin/env node

description: 'ID of Organization destinaiton Space should be created in. Only required if destination Spacen to specified and your user is in multiple organizations.'
})
.options('only-content-types', {
description: 'Only copy the Content Types from the source to the destination space'
});
var argv = yargs.argv;

@@ -55,2 +59,3 @@

var destinationOrganizationId = argv['destination-organization-id'];
var onlyContentTypes = argv['only-content-types'];

@@ -67,6 +72,15 @@ var client = contentful.createClient({

client.getSpace(sourceSpaceId).catch(function(error) {
client.getSpace(sourceSpaceId)
.catch(reportInvalidSpace)
.then(getDestinationSpace)
.tap(logSummary)
.spread(clone)
.done();
function reportInvalidSpace (error) {
console.log('Could not find source Space %s using access token %s', sourceSpaceId, accessToken);
throw error;
}).then(function(sourceSpace) {
}
function getDestinationSpace (sourceSpace) {
var destinationSpacePromise;

@@ -85,8 +99,12 @@

return [sourceSpace, destinationSpacePromise];
}).spread(function(sourceSpace, destinationSpace) {
return Promise.all([sourceSpace, destinationSpacePromise]);
}
function logSummary (spaces) {
console.log('Cloning from Space "%s" (%s) to "%s" (%s)',
sourceSpace.name, sourceSpace.sys.id,
destinationSpace.name, destinationSpace.sys.id);
spaces[0].name, spaces[0].sys.id,
spaces[1].name, spaces[1].sys.id);
}
function clone (sourceSpace, destinationSpace) {
return sourceSpace.getContentTypes({

@@ -107,2 +125,6 @@ limit: 1000

}).then(function() {
if (onlyContentTypes) {
return;
}
return forEachAsset(sourceSpace, function(asset) {

@@ -151,2 +173,6 @@ console.log('Creating Asset %s', asset.sys.id);

}).then(function() {
if (onlyContentTypes) {
return;
}
var sourceEntries = [];

@@ -174,3 +200,3 @@ return forEachEntry(sourceSpace, function(entry) {

});
}).done();
}

@@ -177,0 +203,0 @@ var limit = 10;

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

var querystring = require('querystring');
var rateLimit = require('./rate-limit');

@@ -62,4 +63,8 @@ // Identifiable

host: 'api.contentful.com',
secure: true
secure: true,
rateLimit: 6
});
// decorate this.request with a rate limiter
this.request = rateLimit(this.options.rateLimit, 1000, this.request);
},

@@ -69,2 +74,3 @@

if (!options) options = {};
if (!options.method) options.method = 'GET';
if (!options.headers) options.headers = {};

@@ -86,2 +92,3 @@ if (!options.query) options.query = {};

var self = this;
return questor(uri, options)

@@ -92,2 +99,7 @@ .then(parseJSONBody)

}, function(response) {
// Rate-limited by the server, retry the request
if (response.status === 429) {
return self.request(path, options);
}
// Otherwise parse, wrap, and rethrow the error
var error = parseJSONBody(response);

@@ -94,0 +106,0 @@ throw new exports.APIError(error, {

4

package.json
{
"name": "contentful-management",
"description": "Client for Contentful's Content Management API",
"version": "0.0.7",
"version": "0.1.0",
"homepage": "https://www.contentful.com/developers/documentation/content-management-api/",

@@ -15,3 +15,3 @@ "main": "index.js",

"redefine": "~0.2.0",
"questor": "1.0.0-alpha.3",
"questor": "1.0.0",
"inherits": "^2.0.1",

@@ -18,0 +18,0 @@ "underscore-contrib": "0.2.2"

@@ -9,2 +9,9 @@ # contentful-management.js

Supported browsers/environments:
- Chrome
- Firefox
- IE10
- node.js >= 0.8
## Install

@@ -77,10 +84,11 @@

### Cloning a Space's Content Model
### Cloning a Space's Content Types Only
[View Source](example/mirror-content-model.js)
Note: Destination Space has to exist. It won't be created by the Script.
If you just want the content types for a space to be cloned, add the `--only-content-types` flag.
``` sh
$ example/mirror-content-model.js $CONTENTFUL_ACCESS_TOKEN $SOURCE_SPACE_ID $DEST_SPACE_ID
$ example/clone-space.js \
--access-token $CONTENTFUL_ACCESS_TOKEN \
--source-space-id $SOURCE_SPACE_ID \
--destination-space-id $DESTINATION_SPACE_ID
--only-content-types
```

@@ -87,0 +95,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