diff --git a/Makefile b/Makefile index be5f060..c46f6dd 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ standalone: dist/wpcom.js install: node_modules index.js clean: - @rm -rf dist index.js + @rm -rf dist index.js index.js.map distclean: clean @rm -rf node_modules diff --git a/dist/wpcom.js b/dist/wpcom.js index ff72bb8..09d14d8 100644 --- a/dist/wpcom.js +++ b/dist/wpcom.js @@ -1 +1,2 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("debug"),require("fs"),require("qs"),require("wpcom-xhr-request")):"function"==typeof define&&define.amd?define(["debug","fs","qs","wpcom-xhr-request"],e):"object"==typeof exports?exports.WPCOM=e(require("debug"),require("fs"),require("qs"),require("wpcom-xhr-request")):t.WPCOM=e(t.debug,t.fs,t.qs,t["wpcom-xhr-request"])}(this,function(t,e,i,s){return function(t){function e(s){if(i[s])return i[s].exports;var o=i[s]={exports:{},id:s,loaded:!1};return t[s].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){function s(t,e){return this instanceof s?("function"==typeof t&&(e=t,t=null),t&&(h("Token defined: %s…",t.substring(0,6)),this.token=t),e?this.request=e:(h("No request handler. Adding default XHR request handler"),this.request=function(e,i){return e=e||{},t&&(e.authToken=t),o(e,i)}),this.req=new c(this),void(this.apiVersion="1.1")):new s(t,e)}var o=i(19),r=i(9),n=i(13),p=i(15),u=i(4),c=i(16),d=i(3),h=i(1)("wpcom"),a=3e4;s.prototype.me=function(){return new r(this)},s.prototype.site=function(t){return new n(t,this)},s.prototype.users=function(){return new p(this)},s.prototype.batch=function(){return new u(this)},s.prototype.freshlyPressed=function(t,e){return this.req.get("/freshly-pressed",t,e)},s.prototype.sendRequest=function(t,e,i,s){var o="WARN! Don use `sendRequest() anymore. Use `this.req` method.";return console&&console.warn?console.warn(o):console.log(o),d.call(this,t,e,i,s)},s.prototype.Promise=function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),s=1;e>s;s++)i[s-1]=arguments[s];return new Promise(function(e,s){t.apply(t,[].concat(i,[function(t,i){t?s(t):e(i)}]))})},Promise.prototype.timeout||(Promise.prototype.timeout=function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?a:arguments[0],i=void 0,s=void 0,o=void 0;return o=new Promise(function(t,i){s=setTimeout(function(){i(new Error("Action timed out while waiting for response."))},e)}),i=function(){return clearTimeout(s),t},Promise.race([this.then(i)["catch"](i),o])}),t.exports=s},function(e,i){e.exports=t},function(t,e,i){function s(t,e,i,o){if(!i)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=o,this._cid=t,this._pid=e,void(this._sid=i)):new s(t,e,i,o)}var o=i(6);i(1)("wpcom:comment");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.get(i,t,e)},s.prototype.replies=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/replies/";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={})),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/posts/"+this._pid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.put(s,t,e,i)},s.prototype.reply=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/delete";return this.wpcom.req.del(i,t,e)},s.prototype.like=function(){return o(this._cid,this._sid,this.wpcom)},s.prototype.likesList=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes";return this.wpcom.req.get(i,t,e)},t.exports=s},function(t,e,i){var s=i(18),o=i(1)("wpcom:send-request"),r=i(1)("wpcom:send-request:res");t.exports=function(t,e,i,n){var p=this;return t="string"==typeof t?{path:t}:t,o("sendRequest(%o)",t.path),t.method=(t.method||"get").toUpperCase(),"function"==typeof e&&(n=e,e={}),"function"==typeof i&&(n=i,i=null),e=e||{},e.apiVersion?(t.apiVersion=e.apiVersion,o("apiVersion: %o",t.apiVersion),delete e.apiVersion):t.apiVersion=this.apiVersion,e.proxyOrigin&&(t.proxyOrigin=e.proxyOrigin,o("proxyOrigin: %o",t.proxyOrigin),delete e.proxyOrigin),e=s.stringify(e,{arrayFormat:"brackets"}),t.query=e,i&&(t.body=i),o("params: %o",t),"function"==typeof n?this.request(t,function(t,e){r(e),n(t,e)}):new Promise(function(e,i){p.request(t,function(t,s){r(s),t?i(t):e(s)})})}},function(t,e,i){function s(t){return this instanceof s?(this.wpcom=t,void(this.urls=[])):new s(t)}i(1)("wpcom:batch");s.prototype.add=function(t){return this.urls.push(t),this},s.prototype.run=function(t,e){return void 0===t&&(t={}),"function"==typeof t&&(e=t,t={}),t.urls=this.urls,this.wpcom.req.get("/batch",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._sid=e,void(this._slug=t)):new s(t,e,i)}i(1)("wpcom:category");s.prototype.slug=function(t){this._slug=t},s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){var s="/sites/"+this._sid+"/categories/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.put(s,t,e,i)},s.prototype["delete"]=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug+"/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`comment id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._cid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:commentlike");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/new";return this.wpcom.req.post(i,t,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e){if(!t)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=e,void(this._sid=t)):new s(t,e)}i(1)("wpcom:follow");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/follows/mine";return this.wpcom.req.get(i,t,e)},s.prototype.follow=s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/follows/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.unfollow=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/follows/mine/delete";return this.wpcom.req.del(i,t,null,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`post id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._pid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:like");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t){return this instanceof s?void(this.wpcom=t):new s(t)}i(1)("wpcom:me");s.prototype.get=function(t,e){return this.wpcom.req.get("/me",t,e)},s.prototype.sites=function(t,e){return this.wpcom.req.get("/me/sites",t,e)},s.prototype.likes=function(t,e){return this.wpcom.req.get("/me/likes",t,e)},s.prototype.groups=function(t,e){return this.wpcom.req.get("/me/groups",t,e)},s.prototype.connections=function(t,e){return this.wpcom.req.get("/me/connections",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){return this instanceof s?(this.wpcom=i,this._sid=e,this._id=t,void(this._id||r("WARN: media `id` is not defined"))):new s(t,e,i)}var o=i(17),r=i(1)("wpcom:media");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.get(i,t,e)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.put(s,t,e,i)},s.prototype.addFiles=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s={path:"/sites/"+this._sid+"/media/new",formData:[]};e=Array.isArray(e)?e:[e];var n,p,u,c,d,h;for(n=0;n %o",d,p[d]),"file"!==d&&(h="attrs["+n+"]["+d+"]",s.formData.push([h,p[d]]));p=p.file,p="string"==typeof p?o.createReadStream(p):p}s.formData.push(["media[]",p])}return this.wpcom.req.post(s,t,null,i)},s.prototype.addUrls=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s,o,r,n,p="/sites/"+this._sid+"/media/new",u={media_urls:[]};for(e=Array.isArray(e)?e:[e],s=0;s1?e-1:0),s=1;e>s;s++)i[s-1]=arguments[s];return new Promise(function(e,s){t.apply(t,[].concat(i,[function(t,i){t?s(t):e(i)}]))})},Promise.prototype.timeout||(Promise.prototype.timeout=function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?a:arguments[0],i=void 0,s=void 0,o=void 0;return o=new Promise(function(t,i){s=setTimeout(function(){i(new Error("Action timed out while waiting for response."))},e)}),i=function(){return clearTimeout(s),t},Promise.race([this.then(i)["catch"](i),o])}),t.exports=s},function(e,i){e.exports=t},function(t,e,i){function s(t,e,i,o){if(!i)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=o,this._cid=t,this._pid=e,void(this._sid=i)):new s(t,e,i,o)}var o=i(6);i(1)("wpcom:comment");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.get(i,t,e)},s.prototype.replies=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/replies/";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={})),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/posts/"+this._pid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.put(s,t,e,i)},s.prototype.reply=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/delete";return this.wpcom.req.del(i,t,e)},s.prototype.like=function(){return o(this._cid,this._sid,this.wpcom)},s.prototype.likesList=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes";return this.wpcom.req.get(i,t,e)},t.exports=s},function(t,e,i){var s=i(18),o=i(1)("wpcom:send-request"),r=i(1)("wpcom:send-request:res");t.exports=function(t,e,i,n){var p=this;return t="string"==typeof t?{path:t}:t,o("sendRequest(%o)",t.path),t.method=(t.method||"get").toUpperCase(),"function"==typeof e&&(n=e,e={}),"function"==typeof i&&(n=i,i=null),e=e||{},e.apiVersion?(t.apiVersion=e.apiVersion,o("apiVersion: %o",t.apiVersion),delete e.apiVersion):t.apiVersion=this.apiVersion,e.proxyOrigin&&(t.proxyOrigin=e.proxyOrigin,o("proxyOrigin: %o",t.proxyOrigin),delete e.proxyOrigin),e=s.stringify(e,{arrayFormat:"brackets"}),t.query=e,i&&(t.body=i),o("params: %o",t),"function"==typeof n?this.request(t,function(t,e){r(e),n(t,e)}):new Promise(function(e,i){p.request(t,function(t,s){r(s),t?i(t):e(s)})})}},function(t,e,i){function s(t){return this instanceof s?(this.wpcom=t,void(this.urls=[])):new s(t)}i(1)("wpcom:batch");s.prototype.add=function(t){return this.urls.push(t),this},s.prototype.run=function(t,e){return void 0===t&&(t={}),"function"==typeof t&&(e=t,t={}),t.urls=this.urls,this.wpcom.req.get("/batch",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._sid=e,void(this._slug=t)):new s(t,e,i)}i(1)("wpcom:category");s.prototype.slug=function(t){this._slug=t},s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){var s="/sites/"+this._sid+"/categories/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.put(s,t,e,i)},s.prototype["delete"]=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug+"/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`comment id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._cid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:commentlike");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/new";return this.wpcom.req.post(i,t,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e){if(!t)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=e,void(this._sid=t)):new s(t,e)}i(1)("wpcom:follow");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/follows/mine";return this.wpcom.req.get(i,t,e)},s.prototype.follow=s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/follows/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.unfollow=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/follows/mine/delete";return this.wpcom.req.del(i,t,null,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`post id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._pid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:like");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t){return this instanceof s?void(this.wpcom=t):new s(t)}i(1)("wpcom:me");s.prototype.get=function(t,e){return this.wpcom.req.get("/me",t,e)},s.prototype.sites=function(t,e){return this.wpcom.req.get("/me/sites",t,e)},s.prototype.likes=function(t,e){return this.wpcom.req.get("/me/likes",t,e)},s.prototype.groups=function(t,e){return this.wpcom.req.get("/me/groups",t,e)},s.prototype.connections=function(t,e){return this.wpcom.req.get("/me/connections",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){return this instanceof s?(this.wpcom=i,this._sid=e,this._id=t,void(this._id||r("WARN: media `id` is not defined"))):new s(t,e,i)}var o=i(17),r=i(1)("wpcom:media");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.get(i,t,e)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.put(s,t,e,i)},s.prototype.addFiles=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s={path:"/sites/"+this._sid+"/media/new",formData:[]};e=Array.isArray(e)?e:[e];var n,p,u,c,d,h;for(n=0;n %o",d,p[d]),"file"!==d&&(h="attrs["+n+"]["+d+"]",s.formData.push([h,p[d]]));p=p.file,p="string"==typeof p?o.createReadStream(p):p}s.formData.push(["media[]",p])}return this.wpcom.req.post(s,t,null,i)},s.prototype.addUrls=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s,o,r,n,p="/sites/"+this._sid+"/media/new",u={media_urls:[]};for(e=Array.isArray(e)?e:[e],s=0;s1?e-1:0),s=1;e>s;s++)i[s-1]=arguments[s];return new Promise(function(e,s){t.apply(t,[].concat(i,[function(t,i){t?s(t):e(i)}]))})},Promise.prototype.timeout||(Promise.prototype.timeout=function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?a:arguments[0],i=void 0,s=void 0,o=void 0;return o=new Promise(function(t,i){s=setTimeout(function(){i(new Error("Action timed out while waiting for response."))},e)}),i=function(){return clearTimeout(s),t},Promise.race([this.then(i)["catch"](i),o])}),t.exports=s},function(t,e){t.exports=require("debug")},function(t,e,i){function s(t,e,i,o){if(!i)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=o,this._cid=t,this._pid=e,void(this._sid=i)):new s(t,e,i,o)}var o=i(6);i(1)("wpcom:comment");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.get(i,t,e)},s.prototype.replies=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/replies/";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={})),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/posts/"+this._pid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.put(s,t,e,i)},s.prototype.reply=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/delete";return this.wpcom.req.del(i,t,e)},s.prototype.like=function(){return o(this._cid,this._sid,this.wpcom)},s.prototype.likesList=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes";return this.wpcom.req.get(i,t,e)},t.exports=s},function(t,e,i){var s=i(18),o=i(1)("wpcom:send-request"),r=i(1)("wpcom:send-request:res");t.exports=function(t,e,i,n){var p=this;return t="string"==typeof t?{path:t}:t,o("sendRequest(%o)",t.path),t.method=(t.method||"get").toUpperCase(),"function"==typeof e&&(n=e,e={}),"function"==typeof i&&(n=i,i=null),e=e||{},e.apiVersion?(t.apiVersion=e.apiVersion,o("apiVersion: %o",t.apiVersion),delete e.apiVersion):t.apiVersion=this.apiVersion,e.proxyOrigin&&(t.proxyOrigin=e.proxyOrigin,o("proxyOrigin: %o",t.proxyOrigin),delete e.proxyOrigin),e=s.stringify(e,{arrayFormat:"brackets"}),t.query=e,i&&(t.body=i),o("params: %o",t),"function"==typeof n?this.request(t,function(t,e){r(e),n(t,e)}):new Promise(function(e,i){p.request(t,function(t,s){r(s),t?i(t):e(s)})})}},function(t,e,i){function s(t){return this instanceof s?(this.wpcom=t,void(this.urls=[])):new s(t)}i(1)("wpcom:batch");s.prototype.add=function(t){return this.urls.push(t),this},s.prototype.run=function(t,e){return void 0===t&&(t={}),"function"==typeof t&&(e=t,t={}),t.urls=this.urls,this.wpcom.req.get("/batch",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._sid=e,void(this._slug=t)):new s(t,e,i)}i(1)("wpcom:category");s.prototype.slug=function(t){this._slug=t},s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){var s="/sites/"+this._sid+"/categories/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.put(s,t,e,i)},s.prototype["delete"]=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug+"/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`comment id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._cid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:commentlike");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/new";return this.wpcom.req.post(i,t,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e){if(!t)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=e,void(this._sid=t)):new s(t,e)}i(1)("wpcom:follow");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/follows/mine";return this.wpcom.req.get(i,t,e)},s.prototype.follow=s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/follows/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.unfollow=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/follows/mine/delete";return this.wpcom.req.del(i,t,null,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`post id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._pid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:like");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t){return this instanceof s?void(this.wpcom=t):new s(t)}i(1)("wpcom:me");s.prototype.get=function(t,e){return this.wpcom.req.get("/me",t,e)},s.prototype.sites=function(t,e){return this.wpcom.req.get("/me/sites",t,e)},s.prototype.likes=function(t,e){return this.wpcom.req.get("/me/likes",t,e)},s.prototype.groups=function(t,e){return this.wpcom.req.get("/me/groups",t,e)},s.prototype.connections=function(t,e){return this.wpcom.req.get("/me/connections",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){return this instanceof s?(this.wpcom=i,this._sid=e,this._id=t,void(this._id||r("WARN: media `id` is not defined"))):new s(t,e,i)}var o=i(17),r=i(1)("wpcom:media");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.get(i,t,e)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.put(s,t,e,i)},s.prototype.addFiles=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s={path:"/sites/"+this._sid+"/media/new",formData:[]};e=Array.isArray(e)?e:[e];var n,p,u,c,d,h;for(n=0;n %o",d,p[d]),"file"!==d&&(h="attrs["+n+"]["+d+"]",s.formData.push([h,p[d]]));p=p.file,p="string"==typeof p?o.createReadStream(p):p}s.formData.push(["media[]",p])}return this.wpcom.req.post(s,t,null,i)},s.prototype.addUrls=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s,o,r,n,p="/sites/"+this._sid+"/media/new",u={media_urls:[]};for(e=Array.isArray(e)?e:[e],s=0;s1?e-1:0),s=1;e>s;s++)i[s-1]=arguments[s];return new Promise(function(e,s){t.apply(t,[].concat(i,[function(t,i){t?s(t):e(i)}]))})},Promise.prototype.timeout||(Promise.prototype.timeout=function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?a:arguments[0],i=void 0,s=void 0,o=void 0;return o=new Promise(function(t,i){s=setTimeout(function(){i(new Error("Action timed out while waiting for response."))},e)}),i=function(){return clearTimeout(s),t},Promise.race([this.then(i)["catch"](i),o])}),t.exports=s},function(t,e){t.exports=require("debug")},function(t,e,i){function s(t,e,i,o){if(!i)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=o,this._cid=t,this._pid=e,void(this._sid=i)):new s(t,e,i,o)}var o=i(6);i(1)("wpcom:comment");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.get(i,t,e)},s.prototype.replies=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/replies/";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={})),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/posts/"+this._pid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid;return this.wpcom.req.put(s,t,e,i)},s.prototype.reply=function(t,e,i){"function"==typeof e&&(i=e,e=t,t={}),e="string"==typeof e?{content:e}:e;var s="/sites/"+this._sid+"/comments/"+this._cid+"/replies/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/delete";return this.wpcom.req.del(i,t,e)},s.prototype.like=function(){return o(this._cid,this._sid,this.wpcom)},s.prototype.likesList=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes";return this.wpcom.req.get(i,t,e)},t.exports=s},function(t,e,i){var s=i(18),o=i(1)("wpcom:send-request"),r=i(1)("wpcom:send-request:res");t.exports=function(t,e,i,n){var p=this;return t="string"==typeof t?{path:t}:t,o("sendRequest(%o)",t.path),t.method=(t.method||"get").toUpperCase(),"function"==typeof e&&(n=e,e={}),"function"==typeof i&&(n=i,i=null),e=e||{},e.apiVersion?(t.apiVersion=e.apiVersion,o("apiVersion: %o",t.apiVersion),delete e.apiVersion):t.apiVersion=this.apiVersion,e.proxyOrigin&&(t.proxyOrigin=e.proxyOrigin,o("proxyOrigin: %o",t.proxyOrigin),delete e.proxyOrigin),e=s.stringify(e,{arrayFormat:"brackets"}),t.query=e,i&&(t.body=i),o("params: %o",t),"function"==typeof n?this.request(t,function(t,e){r(e),n(t,e)}):new Promise(function(e,i){p.request(t,function(t,s){r(s),t?i(t):e(s)})})}},function(t,e,i){function s(t){return this instanceof s?(this.wpcom=t,void(this.urls=[])):new s(t)}i(1)("wpcom:batch");s.prototype.add=function(t){return this.urls.push(t),this},s.prototype.run=function(t,e){return void 0===t&&(t={}),"function"==typeof t&&(e=t,t={}),t.urls=this.urls,this.wpcom.req.get("/batch",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._sid=e,void(this._slug=t)):new s(t,e,i)}i(1)("wpcom:category");s.prototype.slug=function(t){this._slug=t},s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e,i){var s="/sites/"+this._sid+"/categories/new";return this.wpcom.req.post(s,t,e,i)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/categories/slug:"+this._slug;return this.wpcom.req.put(s,t,e,i)},s.prototype["delete"]=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/categories/slug:"+this._slug+"/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`comment id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._cid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:commentlike");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/new";return this.wpcom.req.post(i,t,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/comments/"+this._cid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t,e){if(!t)throw new Error("`site id` is not correctly defined");return this instanceof s?(this.wpcom=e,void(this._sid=t)):new s(t,e)}i(1)("wpcom:follow");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/follows/mine";return this.wpcom.req.get(i,t,e)},s.prototype.follow=s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/follows/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.unfollow=s.prototype.del=function(t,e){var i="/sites/"+this._sid+"/follows/mine/delete";return this.wpcom.req.del(i,t,null,e)},t.exports=s},function(t,e,i){function s(t,e,i){if(!e)throw new Error("`site id` is not correctly defined");if(!t)throw new Error("`post id` is not correctly defined");return this instanceof s?(this.wpcom=i,this._pid=t,void(this._sid=e)):new s(t,e,i)}i(1)("wpcom:like");s.prototype.mine=s.prototype.state=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine";return this.wpcom.req.get(i,t,e)},s.prototype.add=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/new";return this.wpcom.req.put(i,t,null,e)},s.prototype.del=s.prototype["delete"]=function(t,e){var i="/sites/"+this._sid+"/posts/"+this._pid+"/likes/mine/delete";return this.wpcom.req.del(i,t,e)},t.exports=s},function(t,e,i){function s(t){return this instanceof s?void(this.wpcom=t):new s(t)}i(1)("wpcom:me");s.prototype.get=function(t,e){return this.wpcom.req.get("/me",t,e)},s.prototype.sites=function(t,e){return this.wpcom.req.get("/me/sites",t,e)},s.prototype.likes=function(t,e){return this.wpcom.req.get("/me/likes",t,e)},s.prototype.groups=function(t,e){return this.wpcom.req.get("/me/groups",t,e)},s.prototype.connections=function(t,e){return this.wpcom.req.get("/me/connections",t,e)},t.exports=s},function(t,e,i){function s(t,e,i){return this instanceof s?(this.wpcom=i,this._sid=e,this._id=t,void(this._id||r("WARN: media `id` is not defined"))):new s(t,e,i)}var o=i(17),r=i(1)("wpcom:media");s.prototype.get=function(t,e){var i="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.get(i,t,e)},s.prototype.update=function(t,e,i){var s="/sites/"+this._sid+"/media/"+this._id;return this.wpcom.req.put(s,t,e,i)},s.prototype.addFiles=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s={path:"/sites/"+this._sid+"/media/new",formData:[]};e=Array.isArray(e)?e:[e];var n,p,u,c,d,h;for(n=0;n %o",d,p[d]),"file"!==d&&(h="attrs["+n+"]["+d+"]",s.formData.push([h,p[d]]));p=p.file,p="string"==typeof p?o.createReadStream(p):p}s.formData.push(["media[]",p])}return this.wpcom.req.post(s,t,null,i)},s.prototype.addUrls=function(t,e,i){void 0===i&&(void 0===e?(e=t,t={}):"function"==typeof e&&(i=e,e=t,t={}));var s,o,r,n,p="/sites/"+this._sid+"/media/new",u={media_urls:[]};for(e=Array.isArray(e)?e:[e],s=0;s