contentful
Advanced tools
Comparing version 2.0.0 to 2.1.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## v2.1.0 | ||
- Allow an agent to be passed down to axios and subsequently to Node's http module (see https://nodejs.org/api/http.html#http_class_http_agent) | ||
## v2.0.0 | ||
@@ -5,0 +8,0 @@ - Updated axios to 0.8.1 (no more auto polyfilled Promises) |
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.contentful = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function createClient(e){return new Client(e||{})}function isParseableResource(e){return e&&e.sys&&e.sys.type in parseableResourceTypes}function parseResource(e){var t=parseableResourceTypes[e.sys.type];return t.parse(e)}function makeSearchResultParser(e){return function(t){walkMutate(t,isParseableResource,parseResource);var n=e.resolveLinks?(0,_contentfulResolveResponse2["default"])(t):t.items;return Object.defineProperties(n,{limit:{value:t.limit,enumerable:!1},skip:{value:t.skip,enumerable:!1},total:{value:t.total,enumerable:!1}}),n}}function stringifyArrayValues(e){return keys(e).reduce(function(t,n){var r=e[n];return t[n]=Array.isArray(r)?r.join(","):r,t},{})}function walkMutate(e,t,n){if(t(e))return n(e);if(e&&"object"==typeof e)for(var r in e)e[r]=walkMutate(e[r],t,n);return e}function nodeify(e,t){return t?e.then(function(e){return t(null,e),e})["catch"](function(e){throw t(e),e}):e}Object.defineProperty(exports,"__esModule",{value:!0});var _slicedToArray=function(){function e(e,t){var n=[],r=!0,s=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(o){s=!0,i=o}finally{try{!r&&u["return"]&&u["return"]()}finally{if(s)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();exports.createClient=createClient;var _axios=require("axios"),_axios2=_interopRequireDefault(_axios),_contentfulResolveResponse=require("contentful-resolve-response"),_contentfulResolveResponse2=_interopRequireDefault(_contentfulResolveResponse),_querystring=require("querystring"),_querystring2=_interopRequireDefault(_querystring),Client=function(){function e(t){var n=t.accessToken,r=t.space,s=t.secure,i=t.host,a=t.headers;if(_classCallCheck(this,e),!n)throw new TypeError("Expected property accessToken");if(!r)throw new TypeError("Expected property space");var u=s===!1,o=i&&i.split(":")||[],l=_slicedToArray(o,2),c=l[0],y=l[1];c=c||"cdn.contentful.com",y=y||(u?80:443),this.options={baseUrl:(u?"http":"https")+"://"+c+":"+y+"/spaces/"+r,accessToken:n,headers:a||{},resolveLinks:!0}}return _createClass(e,[{key:"_request",value:function(e,t){t||(t={}),t.access_token=this.options.accessToken;var n={headers:this.options.headers,method:"get",url:""+this.options.baseUrl+e+"?"+_querystring2["default"].stringify(t)};return n.headers["Content-Type"]="application/vnd.contentful.delivery.v1+json",(0,_axios2["default"])(n).then(function(e){return e.data})["catch"](function(e){throw e.data})}},{key:"asset",value:function(e,t){return nodeify(this._request("/assets/"+e).then(parseResource),t)}},{key:"assets",value:function(e,t){var n=new Query(e),r=this._request("/assets",n).then(makeSearchResultParser({resolveLinks:this.options.resolveLinks}));return nodeify(r,t)}},{key:"contentType",value:function(e,t){var n=this._request("/content_types/"+e).then(ContentType.parse);return nodeify(n,t)}},{key:"contentTypes",value:function(e,t){var n=new Query(e),r=this._request("/content_types",n).then(makeSearchResultParser({resolveLinks:this.options.resolveLinks}));return nodeify(r,t)}},{key:"entry",value:function(e,t){var n=this._request("/entries/"+e).then(Entry.parse);return nodeify(n,t)}},{key:"entries",value:function(e,t){var n=new Query(e),r=this._request("/entries",n).then(makeSearchResultParser({resolveLinks:this.options.resolveLinks}));return nodeify(r,t)}},{key:"space",value:function(e){return nodeify(this._request(""),e)}},{key:"_pagedSync",value:function(e){var t=this;return this._request("/sync",e.query).then(function(n){return e.append(n),e.done?{items:e.items,nextSyncToken:e.nextSyncToken}:t._pagedSync(e)})}},{key:"sync",value:function(e,t){if(!e||!e.initial&&!e.nextSyncToken)throw new Error("Please provide either the initial flag or a nextSyncToken for syncing");e.nextSyncToken&&(e.sync_token=e.nextSyncToken,delete e.initial,delete e.nextSyncToken);var n=new Query(e),r=makeSearchResultParser({resolveLinks:!1}),s=this._pagedSync(new Sync(n)).then(function(e){return e.items=r(e),e});return nodeify(s,t)}}]),e}(),Asset=function(){function e(t){var n=t.sys,r=t.fields;_classCallCheck(this,e),this.sys=new Sys(n),this.fields=r}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Entry=function(){function e(t){var n=t.sys,r=t.fields;_classCallCheck(this,e),this.sys=new Sys(n),this.fields=r}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),ContentType=function(){function e(t){var n=t.sys,r=t.fields,s=t.name,i=t.displayField;_classCallCheck(this,e),this.sys=new Sys(n),this.name=s,this.displayField=i,this.fields=r&&r.map(Field.parse)}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Field=function(){function e(t){_classCallCheck(this,e);for(var n in t)this[n]=t[n]}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Query=function(){function e(t){_classCallCheck(this,e);for(var n in t)this[n]=t[n]}return _createClass(e,[{key:"toQueryString",value:function(){return _querystring2["default"].stringify(this)}}],[{key:"parse",value:function(t){return new e(stringifyArrayValues(t))}}]),e}(),Space=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,e);for(var n in t)this[n]=t[n]}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Sys=function(){function e(t){var n=t.id,r=t.revision,s=t.type,i=t.locale,a=t.contentType,u=t.createdAt,o=(t.linkType,t.updatedAt),l=t.space;_classCallCheck(this,e),this.id=n,this.revision=r,this.type=s,this.locale=i,this.space=l&&Link.parse(l),this.contentType=a&&new Link(a),this.createdAt=u&&new Date(u),this.updatedAt=o&&new Date(o)}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Link=function(){function e(t){var n=t.sys;_classCallCheck(this,e),this.sys=new Sys(n)}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Sync=function(){function e(t){_classCallCheck(this,e),this.query=t,this.items=[],this.done=!1}return _createClass(e,[{key:"append",value:function(e){var t=this;if(this.items=this.items.concat(e.items),e.nextPageUrl){var n=e.nextPageUrl.split("?");this.query=Object.keys(this.query).reduce(function(e,n){return"initial"!==n&&"type"!==n&&"sync_token"!==n&&(e[n]=t.query[n]),e},{}),this.query.sync_token=_querystring2["default"].parse(n[1]).sync_token}else if(e.nextSyncUrl){var r=e.nextSyncUrl.split("?");this.nextSyncToken=_querystring2["default"].parse(r[1]).sync_token,this.done=!0}}}]),e}(),parseableResourceTypes={Asset:Asset,ContentType:ContentType,Entry:Entry,Space:Space}; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function createClient(e){return new Client(e||{})}function isParseableResource(e){return e&&e.sys&&e.sys.type in parseableResourceTypes}function parseResource(e){var t=parseableResourceTypes[e.sys.type];return t.parse(e)}function makeSearchResultParser(e){return function(t){walkMutate(t,isParseableResource,parseResource);var n=e.resolveLinks?(0,_contentfulResolveResponse2["default"])(t):t.items;return Object.defineProperties(n,{limit:{value:t.limit,enumerable:!1},skip:{value:t.skip,enumerable:!1},total:{value:t.total,enumerable:!1}}),n}}function stringifyArrayValues(e){return keys(e).reduce(function(t,n){var r=e[n];return t[n]=Array.isArray(r)?r.join(","):r,t},{})}function walkMutate(e,t,n){if(t(e))return n(e);if(e&&"object"==typeof e)for(var r in e)e[r]=walkMutate(e[r],t,n);return e}function nodeify(e,t){return t?e.then(function(e){return t(null,e),e})["catch"](function(e){throw t(e),e}):e}Object.defineProperty(exports,"__esModule",{value:!0});var _slicedToArray=function(){function e(e,t){var n=[],r=!0,s=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(o){s=!0,i=o}finally{try{!r&&u["return"]&&u["return"]()}finally{if(s)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();exports.createClient=createClient;var _axios=require("axios"),_axios2=_interopRequireDefault(_axios),_contentfulResolveResponse=require("contentful-resolve-response"),_contentfulResolveResponse2=_interopRequireDefault(_contentfulResolveResponse),_querystring=require("querystring"),_querystring2=_interopRequireDefault(_querystring),Client=function(){function e(t){var n=t.accessToken,r=t.space,s=t.secure,i=t.host,a=t.headers,u=t.agent;if(_classCallCheck(this,e),!n)throw new TypeError("Expected property accessToken");if(!r)throw new TypeError("Expected property space");var o=s===!1,l=i&&i.split(":")||[],c=_slicedToArray(l,2),y=c[0],f=c[1];y=y||"cdn.contentful.com",f=f||(o?80:443),this.options={baseUrl:(o?"http":"https")+"://"+y+":"+f+"/spaces/"+r,accessToken:n,headers:a||{},resolveLinks:!0},this.agent=u}return _createClass(e,[{key:"_request",value:function(e,t){t||(t={}),t.access_token=this.options.accessToken;var n={headers:this.options.headers,method:"get",url:""+this.options.baseUrl+e+"?"+_querystring2["default"].stringify(t)};return this.agent&&(n.agent=this.agent),n.headers["Content-Type"]="application/vnd.contentful.delivery.v1+json",(0,_axios2["default"])(n).then(function(e){return e.data})["catch"](function(e){throw e.data})}},{key:"asset",value:function(e,t){return nodeify(this._request("/assets/"+e).then(parseResource),t)}},{key:"assets",value:function(e,t){var n=new Query(e),r=this._request("/assets",n).then(makeSearchResultParser({resolveLinks:this.options.resolveLinks}));return nodeify(r,t)}},{key:"contentType",value:function(e,t){var n=this._request("/content_types/"+e).then(ContentType.parse);return nodeify(n,t)}},{key:"contentTypes",value:function(e,t){var n=new Query(e),r=this._request("/content_types",n).then(makeSearchResultParser({resolveLinks:this.options.resolveLinks}));return nodeify(r,t)}},{key:"entry",value:function(e,t){var n=this._request("/entries/"+e).then(Entry.parse);return nodeify(n,t)}},{key:"entries",value:function(e,t){var n=new Query(e),r=this._request("/entries",n).then(makeSearchResultParser({resolveLinks:this.options.resolveLinks}));return nodeify(r,t)}},{key:"space",value:function(e){return nodeify(this._request(""),e)}},{key:"_pagedSync",value:function(e){var t=this;return this._request("/sync",e.query).then(function(n){return e.append(n),e.done?{items:e.items,nextSyncToken:e.nextSyncToken}:t._pagedSync(e)})}},{key:"sync",value:function(e,t){if(!e||!e.initial&&!e.nextSyncToken)throw new Error("Please provide either the initial flag or a nextSyncToken for syncing");e.nextSyncToken&&(e.sync_token=e.nextSyncToken,delete e.initial,delete e.nextSyncToken);var n=new Query(e),r=makeSearchResultParser({resolveLinks:!1}),s=this._pagedSync(new Sync(n)).then(function(e){return e.items=r(e),e});return nodeify(s,t)}}]),e}(),Asset=function(){function e(t){var n=t.sys,r=t.fields;_classCallCheck(this,e),this.sys=new Sys(n),this.fields=r}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Entry=function(){function e(t){var n=t.sys,r=t.fields;_classCallCheck(this,e),this.sys=new Sys(n),this.fields=r}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),ContentType=function(){function e(t){var n=t.sys,r=t.fields,s=t.name,i=t.displayField;_classCallCheck(this,e),this.sys=new Sys(n),this.name=s,this.displayField=i,this.fields=r&&r.map(Field.parse)}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Field=function(){function e(t){_classCallCheck(this,e);for(var n in t)this[n]=t[n]}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Query=function(){function e(t){_classCallCheck(this,e);for(var n in t)this[n]=t[n]}return _createClass(e,[{key:"toQueryString",value:function(){return _querystring2["default"].stringify(this)}}],[{key:"parse",value:function(t){return new e(stringifyArrayValues(t))}}]),e}(),Space=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,e);for(var n in t)this[n]=t[n]}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Sys=function(){function e(t){var n=t.id,r=t.revision,s=t.type,i=t.locale,a=t.contentType,u=t.createdAt,o=(t.linkType,t.updatedAt),l=t.space;_classCallCheck(this,e),this.id=n,this.revision=r,this.type=s,this.locale=i,this.space=l&&Link.parse(l),this.contentType=a&&new Link(a),this.createdAt=u&&new Date(u),this.updatedAt=o&&new Date(o)}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Link=function(){function e(t){var n=t.sys;_classCallCheck(this,e),this.sys=new Sys(n)}return _createClass(e,null,[{key:"parse",value:function(t){return new e(t)}}]),e}(),Sync=function(){function e(t){_classCallCheck(this,e),this.query=t,this.items=[],this.done=!1}return _createClass(e,[{key:"append",value:function(e){var t=this;if(this.items=this.items.concat(e.items),e.nextPageUrl){var n=e.nextPageUrl.split("?");this.query=Object.keys(this.query).reduce(function(e,n){return"initial"!==n&&"type"!==n&&"sync_token"!==n&&(e[n]=t.query[n]),e},{}),this.query.sync_token=_querystring2["default"].parse(n[1]).sync_token}else if(e.nextSyncUrl){var r=e.nextSyncUrl.split("?");this.nextSyncToken=_querystring2["default"].parse(r[1]).sync_token,this.done=!0}}}]),e}(),parseableResourceTypes={Asset:Asset,ContentType:ContentType,Entry:Entry,Space:Space}; | ||
@@ -4,0 +4,0 @@ |
@@ -36,2 +36,3 @@ "use strict"; | ||
var headers = _ref.headers; | ||
var agent = _ref.agent; | ||
@@ -66,2 +67,4 @@ _classCallCheck(this, Client); | ||
}; | ||
this.agent = agent; | ||
} | ||
@@ -84,2 +87,4 @@ | ||
if (this.agent) params.agent = this.agent; | ||
params.headers["Content-Type"] = "application/vnd.contentful.delivery.v1+json"; | ||
@@ -86,0 +91,0 @@ |
@@ -12,3 +12,3 @@ 'use strict'; | ||
class Client { | ||
constructor ({accessToken, space, secure, host, headers}) { | ||
constructor ({accessToken, space, secure, host, headers, agent}) { | ||
if (!accessToken) { | ||
@@ -34,2 +34,4 @@ throw new TypeError('Expected property accessToken'); | ||
}; | ||
this.agent = agent; | ||
} | ||
@@ -50,2 +52,4 @@ | ||
if(this.agent) params.agent = this.agent; | ||
params.headers['Content-Type'] = 'application/vnd.contentful.delivery.v1+json'; | ||
@@ -52,0 +56,0 @@ |
{ | ||
"name": "contentful", | ||
"description": "Client for Contentful's Content Delivery API", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"homepage": "https://www.contentful.com/developers/documentation/content-delivery-api/", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -65,6 +65,12 @@ # contentful.js | ||
// Resolve links to entries and assets | ||
resolveLinks: true | ||
resolveLinks: true, | ||
// Optional HTTP agent for Node's http module | ||
agent: agentInstance | ||
}); | ||
``` | ||
If you'd like to use contentful.js with an http proxy, look into [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent). If you pass down an agent through the relevant initialization option it gets passed down to axios and subsequently to Node's http module. | ||
### Client#space() -> SpacePromise | ||
@@ -71,0 +77,0 @@ |
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
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
196412
2309
500