contentful-management
Advanced tools
Comparing version 0.0.7 to 0.1.0
@@ -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; |
14
index.js
@@ -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, { |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
424321
24
5728
133
7
4
14
5
8
94
+ Addedbluebird@2.11.0(transitive)
+ Addedquestor@1.0.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstream-browserify@3.0.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedbluebird@0.11.6(transitive)
- Removedprocess@0.5.2(transitive)
- Removedquestor@1.0.0-alpha.3(transitive)
- Removedstream-browserify@0.1.3(transitive)
Updatedquestor@1.0.0