contentful
Advanced tools
Comparing version 0.1.2 to 1.0.0
109
index.js
'use strict'; | ||
var _ = require('lodash'); | ||
var questor = require('questor'); | ||
var axios = require('axios'); | ||
var redefine = require('redefine'); | ||
@@ -20,29 +20,30 @@ var resolveResponse = require('contentful-resolve-response'); | ||
request: function(path, options) { | ||
if (!options) options = {}; | ||
if (!options.headers) options.headers = {}; | ||
if (!options.query) options.query = {}; | ||
options.headers['Content-Type'] = 'application/vnd.contentful.delivery.v1+json'; | ||
options.query.access_token = this.options.accessToken; | ||
_request: function(path, query) { | ||
if (!query) query = {}; | ||
query.access_token = this.options.accessToken; | ||
var uri = [ | ||
this.options.secure ? 'https' : 'http', | ||
'://', | ||
_.first(this.options.host.split(':')), | ||
':', | ||
this.options.secure ? '443' : '80', | ||
'/spaces/', | ||
this.options.space, | ||
path, | ||
'?', | ||
querystring.stringify(options.query) | ||
].join(''); | ||
var params = { | ||
headers: {}, | ||
method: 'get', | ||
url: [ | ||
this.options.secure ? 'https' : 'http', | ||
'://', | ||
_.first(this.options.host.split(':')), | ||
':', | ||
this.options.secure ? '443' : '80', | ||
'/spaces/', | ||
this.options.space, | ||
path, | ||
'?', | ||
querystring.stringify(query) | ||
].join('') | ||
}; | ||
params.headers['Content-Type'] = 'application/vnd.contentful.delivery.v1+json'; | ||
return questor(uri, options) | ||
.then(parseJSONBody) | ||
.catch(Error, function(error) { | ||
throw error; | ||
return axios(params) | ||
.then(function (response) { | ||
return response.data; | ||
}) | ||
.catch(function(error) { | ||
throw parseJSONBody(error); | ||
.catch(function (error) { | ||
throw error.data; | ||
}); | ||
@@ -52,3 +53,6 @@ }, | ||
asset: function(id, callback) { | ||
return this.request('/assets/' + id).then(Asset.parse).nodeify(callback); | ||
return nodeify( | ||
this._request('/assets/' + id).then(Asset.parse), | ||
callback | ||
); | ||
}, | ||
@@ -58,11 +62,11 @@ | ||
var query = Query.parse(object); | ||
return this.request('/assets', {query: query}) | ||
.then(_.partial(SearchResult.parse, Asset)) | ||
.nodeify(callback); | ||
var deferred = this._request('/assets', query) | ||
.then(_.partial(SearchResult.parse)); | ||
return nodeify(deferred, callback); | ||
}, | ||
contentType: function(id, callback) { | ||
return this.request('/content_types/' + id) | ||
.then(ContentType.parse) | ||
.nodeify(callback); | ||
var deferred = this._request('/content_types/' + id) | ||
.then(ContentType.parse); | ||
return nodeify(deferred, callback); | ||
}, | ||
@@ -72,11 +76,11 @@ | ||
var query = Query.parse(object); | ||
return this.request('/content_types', {query: query}) | ||
.then(_.partial(SearchResult.parse, ContentType)) | ||
.nodeify(callback); | ||
var deferred = this._request('/content_types', query) | ||
.then(_.partial(SearchResult.parse)); | ||
return nodeify(deferred, callback); | ||
}, | ||
entry: function(id, callback) { | ||
return this.request('/entries/' + id) | ||
.then(Entry.parse) | ||
.nodeify(callback); | ||
var deferred = this._request('/entries/' + id) | ||
.then(Entry.parse); | ||
return nodeify(deferred, callback); | ||
}, | ||
@@ -86,9 +90,9 @@ | ||
var query = Query.parse(object); | ||
return this.request('/entries', {query: query}) | ||
.then(_.partial(SearchResult.parse, Entry)) | ||
.nodeify(callback); | ||
var deferred = this._request('/entries', query) | ||
.then(_.partial(SearchResult.parse)); | ||
return nodeify(deferred, callback); | ||
}, | ||
space: function(callback) { | ||
return this.request('').nodeify(callback); | ||
return nodeify(this._request(''), callback); | ||
} | ||
@@ -150,3 +154,3 @@ }); | ||
statics: { | ||
parse: function(ItemType, object) { | ||
parse: function(object) { | ||
walkMutate(object, isParseableResource, parseResource); | ||
@@ -264,6 +268,2 @@ var items = resolveResponse(object); | ||
function parseJSONBody(response) { | ||
return JSON.parse(response.body); | ||
} | ||
function stringifyArrayValues(object) { | ||
@@ -289,1 +289,16 @@ return _.reduce(object, function(object, value, key) { | ||
} | ||
function nodeify(deferred, callback) { | ||
if(callback) { | ||
return deferred | ||
.then(function (response) { | ||
callback(null, response); | ||
return response; | ||
}) | ||
.catch(function (error) { | ||
callback(error); | ||
throw error; | ||
}); | ||
} | ||
return deferred; | ||
} |
{ | ||
"name": "contentful", | ||
"description": "Client for Contentful's Content Delivery API", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"homepage": "https://www.contentful.com/developers/documentation/content-delivery-api/", | ||
"main": "index.js", | ||
"browser": { | ||
"questor": "./questor.min.js" | ||
}, | ||
"repository": "git@github.com:contentful/contentful.js.git", | ||
@@ -14,5 +11,5 @@ "author": "Stephan Seidt <stephan@contentful.com>", | ||
"dependencies": { | ||
"axios": "^0.5.2", | ||
"contentful-resolve-response": "~0.1.0", | ||
"lodash": "~2.4.1", | ||
"questor": "1.0.0-alpha.2", | ||
"redefine": "~0.2.0" | ||
@@ -22,13 +19,13 @@ }, | ||
"buster": "~0.7.6", | ||
"bluebird": "~1.2.4", | ||
"bluebird": "^2.0.0", | ||
"envify": "~1.0.1", | ||
"testem": "~0.6.2", | ||
"browserstack-cli": "~0.3.1", | ||
"browserify": "~3.20.0" | ||
"browserify": "~3.20.0", | ||
"saucie": "^0.1.0" | ||
}, | ||
"scripts": { | ||
"prepare-browser-test": "browserify -d -t envify -x buster test/helper.js > test/bundle-helper.js", | ||
"test": "testem ci -P 6", | ||
"test-local": "testem" | ||
"ci": "testem ci -P 6", | ||
"test": "testem" | ||
} | ||
} |
@@ -55,3 +55,6 @@ # contentful.js | ||
// Enable or disable SSL. Enabled by default. | ||
secure: true | ||
secure: true, | ||
// Set an alternate hostname, default shown. | ||
host: 'cdn.contentful.com' | ||
}); | ||
@@ -58,0 +61,0 @@ |
@@ -9,6 +9,6 @@ 'use strict'; | ||
global.assert = buster.assert; | ||
global.refute = buster.refute; | ||
global.assert = global.buster.assert; | ||
global.refute = global.buster.refute; | ||
global.util = require('./util'); | ||
global.client = global.util.client; |
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
96
7
325903
4530
+ Addedaxios@^0.5.2
+ Addedaxios@0.5.4(transitive)
+ Addedes6-promise@2.3.0(transitive)
- Removedquestor@1.0.0-alpha.2
- Removedbl@0.7.0(transitive)
- Removedbluebird@0.11.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedprocess@0.5.2(transitive)
- Removedquestor@1.0.0-alpha.2(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedstream-browserify@0.1.3(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedunderscore@1.13.7(transitive)
- Removedunderscore-contrib@0.2.2(transitive)