contentful-management
Advanced tools
Comparing version 0.0.6 to 0.0.7
41
index.js
@@ -89,3 +89,16 @@ 'use strict'; | ||
var error = parseJSONBody(response); | ||
throw new Error('message' in error ? error.message : response.body); | ||
throw new exports.APIError(error, { | ||
method: options.method, | ||
uri: uri, | ||
body: options.body | ||
}); | ||
}) | ||
.catch(SyntaxError, function (err) { | ||
// Attach request info if JSON.parse throws | ||
err.request = { | ||
method: options.method, | ||
uri: uri, | ||
body: options.body | ||
}; | ||
throw err; | ||
}); | ||
@@ -452,5 +465,4 @@ }, | ||
walkMutate(object, isParseableResource, _.partial(parseResource, client)); | ||
var items = resolveLinks(object); | ||
return redefine( | ||
items, { | ||
object.items, { | ||
limit: object.limit, | ||
@@ -521,2 +533,4 @@ skip: object.skip, | ||
exports.APIError = require('./api-error'); | ||
function compacto(object) { | ||
@@ -566,23 +580,2 @@ return _.reduce(object, function(compacted, value, key) { | ||
function resolveLinks(response) { | ||
walkMutate(response, isLink, function(link) { | ||
return getLink(response, link) || link; | ||
}); | ||
return response.items; | ||
} | ||
function isLink(object) { | ||
return _.getPath(object, ['sys', 'type']) === 'Link'; | ||
} | ||
function getLink(response, link) { | ||
var type = link.sys.linkType; | ||
var id = link.sys.id; | ||
var pred = function(resource) { | ||
return resource.sys.type === type && resource.sys.id === id; | ||
}; | ||
return _.find(response.items, pred) || | ||
response.includes && _.find(response.includes[type], pred); | ||
} | ||
function walkMutate(input, pred, mutator) { | ||
@@ -589,0 +582,0 @@ if (pred(input)) |
{ | ||
"name": "contentful-management", | ||
"description": "Client for Contentful's Content Management API", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"homepage": "https://www.contentful.com/developers/documentation/content-management-api/", | ||
@@ -16,11 +16,14 @@ "main": "index.js", | ||
"questor": "1.0.0-alpha.3", | ||
"inherits": "^2.0.1", | ||
"underscore-contrib": "0.2.2" | ||
}, | ||
"devDependencies": { | ||
"bluebird": "~2.1.2", | ||
"browserify": "~3.20.0", | ||
"browserstack-cli": "~0.3.1", | ||
"buster": "~0.7.6", | ||
"bluebird": "~1.0.0", | ||
"envify": "~1.0.1", | ||
"lodash": "~2.4.1", | ||
"testem": "~0.6.2", | ||
"browserstack-cli": "~0.3.1", | ||
"browserify": "~3.20.0" | ||
"yargs": "~1.2.1" | ||
}, | ||
@@ -27,0 +30,0 @@ "scripts": { |
@@ -56,6 +56,26 @@ # contentful-management.js | ||
#### Cloning a Space's Content Model | ||
### Cloning a Space | ||
[View Source](https://github.com/contentful/contentful-management.js/blob/master/example/mirror-content-model.js) | ||
[View Source](example/clone-space.js) | ||
This clones a Space's complete content model & content. | ||
It's intended to be used to create one-time clones of Spaces, | ||
not for synchronization. | ||
``` sh | ||
$ example/clone-space.js \ | ||
--access-token $CONTENTFUL_ACCESS_TOKEN \ | ||
--source-space-id $SOURCE_SPACE_ID \ | ||
--destination-space-id $DESTINATION_SPACE_ID | ||
``` | ||
Omit the `destination-space-id` parameter to make the script create a | ||
Space. When doing that you might have to specify a | ||
`destination-organization-id` parameter if your user is in multiple | ||
organizations. | ||
### Cloning a Space's Content Model | ||
[View Source](example/mirror-content-model.js) | ||
Note: Destination Space has to exist. It won't be created by the Script. | ||
@@ -67,2 +87,26 @@ | ||
### Migrating Entry fields | ||
Sometimes you need to migrate content from one field to another. | ||
This is a script which migrates all values from one field to another | ||
field, using a specific mapping function if it's provided. | ||
It'll do this for each entry of a specific Content Type in a Space, | ||
going through it slice by slice. | ||
Currently this supports mapping from Text to Symbol. | ||
But it would be very simple to convert e.g. numbers to symbols | ||
or even location strings to locations by geocoding. | ||
PRs are very welcome! | ||
[View Source](example/migrate-fields.js) | ||
``` sh | ||
$ example/migrate-fields.js \ | ||
--access-token $CONTENTFUL_MANAGEMENT_API_ACCESS_TOKEN \ | ||
--space-id $SPACE_ID \ | ||
--content-type-id $CONTENT_TYPE_ID \ | ||
--source-field-id $SOURCE_FIELD_ID \ | ||
--destination-field-id $DESTINATION_FIELD_ID | ||
``` | ||
## Unit Tests | ||
@@ -69,0 +113,0 @@ |
@@ -29,3 +29,3 @@ 'use strict'; | ||
return client.updateSpace(space).then(function(space) { | ||
assert.equals(space.sys.version, 1); | ||
assert.equals(space.sys.version, 2); | ||
}); | ||
@@ -32,0 +32,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
422018
22
5645
125
4
8
+ Addedinherits@^2.0.1