UNPKG

ravelry

Version:

Development for the Ravelry module.

1 lines 33.4 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=7)}([function(t,e){t.exports=require("querystring")},function(t,e){t.exports=require("url")},function(t,e){t.exports=require("https")},function(t,e,n){var r=n(4),o=n(10),s=n(5),u=n(2),i=n(1),a=n(0),c=n(6);e.OAuth=function(t,e,n,r,o,s,u,i,a){if(this._isEcho=!1,this._requestUrl=t,this._accessUrl=e,this._consumerKey=n,this._consumerSecret=this._encodeData(r),"RSA-SHA1"==u&&(this._privateKey=r),this._version=o,this._authorize_callback=void 0===s?"oob":s,"PLAINTEXT"!=u&&"HMAC-SHA1"!=u&&"RSA-SHA1"!=u)throw new Error("Un-supported signature method: "+u);this._signatureMethod=u,this._nonceSize=i||32,this._headers=a||{Accept:"*/*",Connection:"close","User-Agent":"Node authentication"},this._clientOptions=this._defaultClientOptions={requestTokenHttpMethod:"POST",accessTokenHttpMethod:"POST",followRedirects:!0},this._oauthParameterSeperator=","},e.OAuthEcho=function(t,e,n,r,o,s,u,i){if(this._isEcho=!0,this._realm=t,this._verifyCredentials=e,this._consumerKey=n,this._consumerSecret=this._encodeData(r),"RSA-SHA1"==s&&(this._privateKey=r),this._version=o,"PLAINTEXT"!=s&&"HMAC-SHA1"!=s&&"RSA-SHA1"!=s)throw new Error("Un-supported signature method: "+s);this._signatureMethod=s,this._nonceSize=u||32,this._headers=i||{Accept:"*/*",Connection:"close","User-Agent":"Node authentication"},this._oauthParameterSeperator=","},e.OAuthEcho.prototype=e.OAuth.prototype,e.OAuth.prototype._getTimestamp=function(){return Math.floor((new Date).getTime()/1e3)},e.OAuth.prototype._encodeData=function(t){return null==t||""==t?"":encodeURIComponent(t).replace(/\!/g,"%21").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")},e.OAuth.prototype._decodeData=function(t){return null!=t&&(t=t.replace(/\+/g," ")),decodeURIComponent(t)},e.OAuth.prototype._getSignature=function(t,e,n,r){var o=this._createSignatureBase(t,e,n);return this._createSignature(o,r)},e.OAuth.prototype._normalizeUrl=function(t){var e=i.parse(t,!0),n="";return e.port&&("http:"==e.protocol&&"80"!=e.port||"https:"==e.protocol&&"443"!=e.port)&&(n=":"+e.port),e.pathname&&""!=e.pathname||(e.pathname="/"),e.protocol+"//"+e.hostname+n+e.pathname},e.OAuth.prototype._isParameterNameAnOAuthParameter=function(t){var e=t.match("^oauth_");return!(!e||"oauth_"!==e[0])},e.OAuth.prototype._buildAuthorizationHeaders=function(t){var e="OAuth ";this._isEcho&&(e+='realm="'+this._realm+'",');for(var n=0;n<t.length;n++)this._isParameterNameAnOAuthParameter(t[n][0])&&(e+=this._encodeData(t[n][0])+'="'+this._encodeData(t[n][1])+'"'+this._oauthParameterSeperator);return e=e.substring(0,e.length-this._oauthParameterSeperator.length)},e.OAuth.prototype._makeArrayOfArgumentsHash=function(t){var e=[];for(var n in t)if(t.hasOwnProperty(n)){var r=t[n];if(Array.isArray(r))for(var o=0;o<r.length;o++)e[e.length]=[n,r[o]];else e[e.length]=[n,r]}return e},e.OAuth.prototype._sortRequestParams=function(t){return t.sort(function(t,e){return t[0]==e[0]?t[1]<e[1]?-1:1:t[0]<e[0]?-1:1}),t},e.OAuth.prototype._normaliseRequestParams=function(t){for(var e=this._makeArrayOfArgumentsHash(t),n=0;n<e.length;n++)e[n][0]=this._encodeData(e[n][0]),e[n][1]=this._encodeData(e[n][1]);e=this._sortRequestParams(e);for(t="",n=0;n<e.length;n++)t+=e[n][0],t+="=",t+=e[n][1],n<e.length-1&&(t+="&");return t},e.OAuth.prototype._createSignatureBase=function(t,e,n){return e=this._encodeData(this._normalizeUrl(e)),n=this._encodeData(n),t.toUpperCase()+"&"+e+"&"+n},e.OAuth.prototype._createSignature=function(t,e){if(void 0===e)e="";else e=this._encodeData(e);var n=this._consumerSecret+"&"+e,s="";return"PLAINTEXT"==this._signatureMethod?s=n:"RSA-SHA1"==this._signatureMethod?(n=this._privateKey||"",s=r.createSign("RSA-SHA1").update(t).sign(n,"base64")):s=r.Hmac?r.createHmac("sha1",n).update(t).digest("base64"):o.HMACSHA1(n,t),s},e.OAuth.prototype.NONCE_CHARS=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"],e.OAuth.prototype._getNonce=function(t){for(var e,n=[],r=this.NONCE_CHARS,o=r.length,s=0;s<t;s++)e=Math.floor(Math.random()*o),n[s]=r[e];return n.join("")},e.OAuth.prototype._createClient=function(t,e,n,r,o,i){var a={host:e,port:t,path:r,method:n,headers:o};return(i?u:s).request(a)},e.OAuth.prototype._prepareParameters=function(t,e,n,r,o){var s,u={oauth_timestamp:this._getTimestamp(),oauth_nonce:this._getNonce(this._nonceSize),oauth_version:this._version,oauth_signature_method:this._signatureMethod,oauth_consumer_key:this._consumerKey};if(t&&(u.oauth_token=t),this._isEcho)s=this._getSignature("GET",this._verifyCredentials,this._normaliseRequestParams(u),e);else{if(o)for(var c in o)o.hasOwnProperty(c)&&(u[c]=o[c]);var p=i.parse(r,!1);if(p.query){var f,h=a.parse(p.query);for(var c in h){var l=h[c];if("object"==typeof l)for(f in l)u[c+"["+f+"]"]=l[f];else u[c]=l}}s=this._getSignature(n,r,this._normaliseRequestParams(u),e)}var d=this._sortRequestParams(this._makeArrayOfArgumentsHash(u));return d[d.length]=["oauth_signature",s],d},e.OAuth.prototype._performSecureRequest=function(t,e,n,r,o,s,u,p){var f=this._prepareParameters(t,e,n,r,o);u||(u="application/x-www-form-urlencoded");var h=i.parse(r,!1);"http:"!=h.protocol||h.port||(h.port=80),"https:"!=h.protocol||h.port||(h.port=443);var l,d,g={},m=this._buildAuthorizationHeaders(f);this._isEcho?g["X-Verify-Credentials-Authorization"]=m:g.Authorization=m,g.Host=h.host;for(var _ in this._headers)this._headers.hasOwnProperty(_)&&(g[_]=this._headers[_]);for(var _ in o)this._isParameterNameAnOAuthParameter(_)&&delete o[_];"POST"!=n&&"PUT"!=n||null!=s||null==o||(s=a.stringify(o).replace(/\!/g,"%21").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")),s?Buffer.isBuffer(s)?g["Content-length"]=s.length:g["Content-length"]=Buffer.byteLength(s):g["Content-length"]=0,g["Content-Type"]=u,h.pathname&&""!=h.pathname||(h.pathname="/"),l=h.query?h.pathname+"?"+h.query:h.pathname,d="https:"==h.protocol?this._createClient(h.port,h.hostname,n,l,g,!0):this._createClient(h.port,h.hostname,n,l,g);var j=this._clientOptions;if(!p)return"POST"!=n&&"PUT"!=n||null==s||""==s||d.write(s),d;var v="",y=this,A=c.isAnEarlyCloseHost(h.hostname),$=!1,O=function(r){$||($=!0,r.statusCode>=200&&r.statusCode<=299?p(null,v,r):(301==r.statusCode||302==r.statusCode)&&j.followRedirects&&r.headers&&r.headers.location?y._performSecureRequest(t,e,n,r.headers.location,o,s,u,p):p({statusCode:r.statusCode,data:v},v,r))};d.on("response",function(t){t.setEncoding("utf8"),t.on("data",function(t){v+=t}),t.on("end",function(){O(t)}),t.on("close",function(){A&&O(t)})}),d.on("error",function(t){$||($=!0,p(t))}),"POST"!=n&&"PUT"!=n||null==s||""==s||d.write(s),d.end()},e.OAuth.prototype.setClientOptions=function(t){var e,n={},r=Object.prototype.hasOwnProperty;for(e in this._defaultClientOptions)r.call(t,e)?n[e]=t[e]:n[e]=this._defaultClientOptions[e];this._clientOptions=n},e.OAuth.prototype.getOAuthAccessToken=function(t,e,n,r){var o={};"function"==typeof n?r=n:o.oauth_verifier=n,this._performSecureRequest(t,e,this._clientOptions.accessTokenHttpMethod,this._accessUrl,o,null,null,function(t,e,n){if(t)r(t);else{var o=a.parse(e),s=o.oauth_token;delete o.oauth_token;var u=o.oauth_token_secret;delete o.oauth_token_secret,r(null,s,u,o)}})},e.OAuth.prototype.getProtectedResource=function(t,e,n,r,o){this._performSecureRequest(n,r,e,t,null,"",null,o)},e.OAuth.prototype.delete=function(t,e,n,r){return this._performSecureRequest(e,n,"DELETE",t,null,"",null,r)},e.OAuth.prototype.get=function(t,e,n,r){return this._performSecureRequest(e,n,"GET",t,null,"",null,r)},e.OAuth.prototype._putOrPost=function(t,e,n,r,o,s,u){var i=null;return"function"==typeof s&&(u=s,s=null),"string"==typeof o||Buffer.isBuffer(o)||(s="application/x-www-form-urlencoded",i=o,o=null),this._performSecureRequest(n,r,t,e,i,o,s,u)},e.OAuth.prototype.put=function(t,e,n,r,o,s){return this._putOrPost("PUT",t,e,n,r,o,s)},e.OAuth.prototype.post=function(t,e,n,r,o,s){return this._putOrPost("POST",t,e,n,r,o,s)},e.OAuth.prototype.getOAuthRequestToken=function(t,e){"function"==typeof t&&(e=t,t={}),this._authorize_callback&&(t.oauth_callback=this._authorize_callback),this._performSecureRequest(null,null,this._clientOptions.requestTokenHttpMethod,this._requestUrl,t,null,null,function(t,n,r){if(t)e(t);else{var o=a.parse(n),s=o.oauth_token,u=o.oauth_token_secret;delete o.oauth_token,delete o.oauth_token_secret,e(null,s,u,o)}})},e.OAuth.prototype.signUrl=function(t,e,n,r){if(void 0===r)r="GET";for(var o=this._prepareParameters(e,n,r,t,{}),s=i.parse(t,!1),u="",a=0;a<o.length;a++)u+=o[a][0]+"="+this._encodeData(o[a][1])+"&";return u=u.substring(0,u.length-1),s.protocol+"//"+s.host+s.pathname+"?"+u},e.OAuth.prototype.authHeader=function(t,e,n,r){if(void 0===r)r="GET";var o=this._prepareParameters(e,n,r,t,{});return this._buildAuthorizationHeaders(o)}},function(t,e){t.exports=require("crypto")},function(t,e){t.exports=require("http")},function(t,e){t.exports.isAnEarlyCloseHost=function(t){return t&&t.match(".*google(apis)?.com$")}},function(t,e,n){var r=n(1),o=n(8),s=n(12),u=n(13),i=n(14),a=n(15),c=n(16),p=n(17),f=n(18),h=n(19),l=n(20),d=n(21),g=n(22),m=n(23),_=n(24),j=n(25),v=n(26),y=n(27),A=n(28),$=n(29),O=n(30),S=n(31),k=n(32),w=n(33),P=n(34),C=n(35),x=n(36),T=n(37),b=n(38),q=n(39),H=n(40),U=n(41),E=n(42),z=n(43),R=n(44),N=n(45),M=n(46),K=n(47),D=n(48),B={_initialized:!1};function I(t,e,n){var I=o(t,e,n);const L=s(B,I);"oauth1.0"===t&&(B.getSignInUrl=function(t){return new Promise(function(e,n){I.getSignInUrl(function(r,o){if(t)return t(r,o);r?n(r):e(o)})})},B.authorize=function(t,e){return new Promise(function(n,o){var s=r.parse(t,!0).query;if(!s.oauth_verifier){var u=new Error("URL does not contain OAuth verifier.");return e?e(u):o(u)}I.getAccessToken(s.oauth_verifier,function(t,r){if(t)return e?e(t):o(t);B.misc.currentUser(function(t,r){return t?e?e(t):o(t):(B.user=r.user,e?e(null,r.user):n(r.user))})})})},B.authorizationMiddleware=function(t){var n=Object.assign({ignorePaths:null,redirect:"/",resume:!1},t),o=null,s=r.parse(e.callbackUrl).path;return function(t,e,u){if(B.user)return u();var i=r.parse(t.url,!0);if(n.ignorePaths&&n.ignorePaths.indexOf(i.pathname)>-1)return u();i.pathname===s?B.authorize(i.path).then(function(t){var r=o||n.redirect;o=null,e.redirect(r)}):B.getSignInUrl().then(function(t){n.resume&&(o=i.path),e.redirect(t)})}}),B.misc=u(B,L),B.currentUser=B.misc.currentUser,B.app=i(B,L),B.bundledItems=a(B,L),B.bundles=c(B,L),B.carts=p(B,L),B.comments=f(B,L),B.deliveries=h(B,L),B.extras=l(B,L),B.favorites=d(B,L),B.fiber=g(B,L),B.forumPosts=m(B,L),B.forums=_(B,L),B.friends=j(B,L),B.groups=v(B,L),B.inStoreSales=y(B,L),B.library=A(B,L),B.messages=$(B,L),B.needles=O(B,L),B.packs=S(B,L),B.pages=k(B,L),B.patternSources=w(B,L),B.patterns=P(B,L),B.people=C(B,L),B.photos=x(B,L),B.productAttachments=T(B,L),B.products=b(B,L),B.projects=q(B,L),B.queue=H(B,L),B.savedSearches=U(B,L),B.shops=E(B,L),B.stash=z(B,L),B.stores=R(B,L),B.topics=N(B,L),B.upload=M(B,L),B.volumes=K(B,L),B.yarns=D(B,L),B._initialized=!0}t.exports={basic:function(t){return B._initialized||I("basic_auth",t),B},oauth1:function(t,e){return B._initialized||I("oauth1.0",t,e),B}}},function(t,e,n){var r=n(2),o=n(9).OAuth,s="https://api.ravelry.com",u="api.ravelry.com";t.exports=function(t,e,n){const i={ravAccessKey:e.ravAccessKey,ravSecretKey:e.ravSecretKey,ravPersonalKey:e.ravPersonalKey,api:{}};var a,c,p,f,h;return"basic_auth"===t&&(!function(t,e){const n={hostname:u,auth:`${e.ravAccessKey}:${e.ravPersonalKey}`};Object.assign(e,{ravPersonalKey:t.ravPersonalKey,auth:{get:function(t){return new Promise(function(e,o){r.get(Object.assign(t,n),function(t){var n="";t.setEncoding("utf8"),t.on("data",t=>{n+=t}),t.on("end",function(){200===t.statusCode?e(JSON.parse(n)):o(n)})})})},post:function(t,e){return new Promise(function(o,s){var u=r.request(Object.assign(t,n),function(t){var e="";t.setEncoding("utf8"),t.on("data",t=>{e+=t}),t.on("end",function(){200===t.statusCode?o(JSON.parse(e)):s(e)})});u.on("error",s),e&&u.write(e),u.end()})},put:function(t,e,o){return new Promise(function(o,s){var u=r.put(Object.assign({path:t},n),function(t){var e="";t.setEncoding("utf8"),t.on("data",t=>{e+=t}),t.on("end",function(){200===t.statusCode?o(JSON.parse(e)):s(e)})});u.on("error",s),e&&u.write(JSON.stringify(e)),u.end()})},delete:function(t,e){return new Promise(function(e,o){var s=r.delete(Object.assign({path:t},n),function(t){var n="";t.setEncoding("utf8"),t.on("data",t=>{n+=t}),t.on("end",function(){200===t.statusCode?e(JSON.parse(n)):o(n)})});s.on("error",o),s.end()})}}})}(e,i),a=i,Object.assign(a.api,{get:function(t){return a.auth.get({method:"GET",path:t})},post:function(t,e){const n={method:"POST",path:t};return e&&(e=JSON.stringify(e),n.headers={"Content-Type":"application/json","Content-Length":e.length}),a.auth.post(n,e)},put:a.auth.put,delete:a.auth.delete})),"oauth1.0"===t&&(p=e,f=n,h=i,Object.assign(h,{ravSecretKey:p.ravSecretKey,callbackUrl:p.callbackUrl,responseUrl:p.responseUrl,auth:new o("https://www.ravelry.com/oauth/request_token"+(f?"?scope="+f.join("+"):""),"https://www.ravelry.com/oauth/access_token",p.ravAccessKey,p.ravSecretKey,"1.0A",p.callbackUrl,"HMAC-SHA1")}),c=i,Object.assign(c.api,{getSignInUrl:function(t){c.auth.getOAuthRequestToken(function(e,n,r,o){if(e)return t(e);c.oauthToken=n,c.oauthSecret=r;var s=c.auth.signUrl("https://www.ravelry.com/oauth/authorize",c.oauthToken,c.oauthSecret,"GET");t(null,s)})},getAccessToken:function(t,e){if(!t)return new Error("You must supply the OAuth verifier from the authorization response");c.auth.getOAuthAccessToken(c.oauthToken,c.oauthSecret,t,function(t,n,r,o){return c.accessToken=n,c.accessSecret=r,e(t,o)})},get:function(t,e){return new Promise(function(e,n){c.auth.get(s+t,c.accessToken,c.accessSecret,function(t,r,o){t?n(t):e(JSON.parse(r))})})},post:function(t,e,n){return new Promise(function(n,r){c.auth.post(s+t,c.accessToken,c.accessSecret,e,"application/json",function(t,e,o){t?r(t):n(JSON.parse(e))})})},put:function(t,e,n){return new Promise(function(n,r){c.auth.put(s+t,c.accessToken,c.accessSecret,e,"application/json",function(t,e,o){t?r(t):n(JSON.parse(e))})})},delete:function(t,e){return new Promise(function(e,n){c.auth.delete(s+t,c.accessToken,c.accessSecret,function(t,r,o){t?n(t):e(JSON.parse(r))})})}})),i.api}},function(t,e,n){e.OAuth=n(3).OAuth,e.OAuthEcho=n(3).OAuthEcho,e.OAuth2=n(11).OAuth2},function(t,e){var n="=";function r(t,e){var n=u(t);n.length>16&&(n=a(n,8*t.length));for(var r=Array(16),o=Array(16),s=0;s<16;s++)r[s]=909522486^n[s],o[s]=1549556828^n[s];var c=a(r.concat(u(e)),512+8*e.length);return i(a(o.concat(c),672))}function o(t){for(var e="",r=t.length,o=0;o<r;o+=3)for(var s=t.charCodeAt(o)<<16|(o+1<r?t.charCodeAt(o+1)<<8:0)|(o+2<r?t.charCodeAt(o+2):0),u=0;u<4;u++)8*o+6*u>8*t.length?e+=n:e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(s>>>6*(3-u)&63);return e}function s(t){for(var e,n,r="",o=-1;++o<t.length;)e=t.charCodeAt(o),n=o+1<t.length?t.charCodeAt(o+1):0,55296<=e&&e<=56319&&56320<=n&&n<=57343&&(e=65536+((1023&e)<<10)+(1023&n),o++),e<=127?r+=String.fromCharCode(e):e<=2047?r+=String.fromCharCode(192|e>>>6&31,128|63&e):e<=65535?r+=String.fromCharCode(224|e>>>12&15,128|e>>>6&63,128|63&e):e<=2097151&&(r+=String.fromCharCode(240|e>>>18&7,128|e>>>12&63,128|e>>>6&63,128|63&e));return r}function u(t){for(var e=Array(t.length>>2),n=0;n<e.length;n++)e[n]=0;for(n=0;n<8*t.length;n+=8)e[n>>5]|=(255&t.charCodeAt(n/8))<<24-n%32;return e}function i(t){for(var e="",n=0;n<32*t.length;n+=8)e+=String.fromCharCode(t[n>>5]>>>24-n%32&255);return e}function a(t,e){t[e>>5]|=128<<24-e%32,t[15+(e+64>>9<<4)]=e;for(var n,r=Array(80),o=1732584193,s=-271733879,u=-1732584194,i=271733878,a=-1009589776,h=0;h<t.length;h+=16){for(var l=o,d=s,g=u,m=i,_=a,j=0;j<80;j++){r[j]=j<16?t[h+j]:f(r[j-3]^r[j-8]^r[j-14]^r[j-16],1);var v=p(p(f(o,5),c(j,s,u,i)),p(p(a,r[j]),(n=j)<20?1518500249:n<40?1859775393:n<60?-1894007588:-899497514));a=i,i=u,u=f(s,30),s=o,o=v}o=p(o,l),s=p(s,d),u=p(u,g),i=p(i,m),a=p(a,_)}return Array(o,s,u,i,a)}function c(t,e,n,r){return t<20?e&n|~e&r:t<40?e^n^r:t<60?e&n|e&r|n&r:e^n^r}function p(t,e){var n=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(n>>16)<<16|65535&n}function f(t,e){return t<<e|t>>>32-e}e.HMACSHA1=function(t,e){return n=e,o(r(s(t),s(n)));var n}},function(t,e,n){var r=n(0),o=(n(4),n(2)),s=n(5),u=n(1),i=n(6);e.OAuth2=function(t,e,n,r,o,s){this._clientId=t,this._clientSecret=e,this._baseSite=n,this._authorizeUrl=r||"/oauth/authorize",this._accessTokenUrl=o||"/oauth/access_token",this._accessTokenName="access_token",this._authMethod="Bearer",this._customHeaders=s||{},this._useAuthorizationHeaderForGET=!1,this._agent=void 0},e.OAuth2.prototype.setAgent=function(t){this._agent=t},e.OAuth2.prototype.setAccessTokenName=function(t){this._accessTokenName=t},e.OAuth2.prototype.setAuthMethod=function(t){this._authMethod=t},e.OAuth2.prototype.useAuthorizationHeaderforGET=function(t){this._useAuthorizationHeaderForGET=t},e.OAuth2.prototype._getAccessTokenUrl=function(){return this._baseSite+this._accessTokenUrl},e.OAuth2.prototype.buildAuthHeader=function(t){return this._authMethod+" "+t},e.OAuth2.prototype._chooseHttpLibrary=function(t){var e=o;return"https:"!=t.protocol&&(e=s),e},e.OAuth2.prototype._request=function(t,e,n,o,s,i){var a=u.parse(e,!0);"https:"!=a.protocol||a.port||(a.port=443);var c=this._chooseHttpLibrary(a),p={};for(var f in this._customHeaders)p[f]=this._customHeaders[f];if(n)for(var f in n)p[f]=n[f];p.Host=a.host,p["User-Agent"]||(p["User-Agent"]="Node-oauth"),o?Buffer.isBuffer(o)?p["Content-Length"]=o.length:p["Content-Length"]=Buffer.byteLength(o):p["Content-length"]=0,!s||"Authorization"in p||(a.query||(a.query={}),a.query[this._accessTokenName]=s);var h=r.stringify(a.query);h&&(h="?"+h);var l={host:a.hostname,port:a.port,path:a.pathname+h,method:t,headers:p};this._executeRequest(c,l,o,i)},e.OAuth2.prototype._executeRequest=function(t,e,n,r){var o=i.isAnEarlyCloseHost(e.host),s=!1;function u(t,e){s||(s=!0,t.statusCode>=200&&t.statusCode<=299||301==t.statusCode||302==t.statusCode?r(null,e,t):r({statusCode:t.statusCode,data:e}))}var a="";this._agent&&(e.agent=this._agent);var c=t.request(e);c.on("response",function(t){t.on("data",function(t){a+=t}),t.on("close",function(e){o&&u(t,a)}),t.addListener("end",function(){u(t,a)})}),c.on("error",function(t){s=!0,r(t)}),"POST"!=e.method&&"PUT"!=e.method||!n||c.write(n),c.end()},e.OAuth2.prototype.getAuthorizeUrl=function(t){return(t=t||{}).client_id=this._clientId,this._baseSite+this._authorizeUrl+"?"+r.stringify(t)},e.OAuth2.prototype.getOAuthAccessToken=function(t,e,n){(e=e||{}).client_id=this._clientId,e.client_secret=this._clientSecret,e["refresh_token"===e.grant_type?"refresh_token":"code"]=t;var o=r.stringify(e);this._request("POST",this._getAccessTokenUrl(),{"Content-Type":"application/x-www-form-urlencoded"},o,null,function(t,e,o){if(t)n(t);else{var s;try{s=JSON.parse(e)}catch(t){s=r.parse(e)}var u=s.access_token,i=s.refresh_token;delete s.refresh_token,n(null,u,i,s)}})},e.OAuth2.prototype.getProtectedResource=function(t,e,n){this._request("GET",t,{},"",e,n)},e.OAuth2.prototype.get=function(t,e,n){if(this._useAuthorizationHeaderForGET){var r={Authorization:this.buildAuthHeader(e)};e=null}else r={};this._request("GET",t,r,"",e,n)}},function(t,e,n){var r=n(0);t.exports=function(t,e){return{get:function(t,n,o){if(2===arguments.length&&"function"==typeof n&&(o=n,n=null),n&&(t+="?"+r.stringify(n)),!o)return e.get(t);e.get(t).then(t=>o(null,t)).catch(t=>o(t))},post:function(t,n,r){if(!r)return e.post(t,n);e.post(t,n).then(t=>r(null,t)).catch(t=>r(t))},put:function(t,n,r){if(!r)return e.put(t,n);e.put(t,n).then(t=>r(null,t)).catch(t=>r(t))},delete:function(t,n){if(!n)return e.delete(t);e.delete(t).then(t=>n(null,t)).catch(t=>n(t))}}}},function(t,e){t.exports=function(t,e){return{colorFamilies:function(t){return e.get("/color_families.json",t)},currentUser:function(n,r){return(r=r||!0)&&t.user?n(null,t.user):e.get("/current_user.json",n)},yarnWeights:function(t){return e.get("/yarn_weights.json",t)}}}},function(t,e,n){var r=n(0);t.exports=function(t,e){return{config:{delete:function(t,n){var r="/app/config/delete.json?keys="+t.join("+");return e.post(r,null,n)},get:function(t,n){var r="";t&&"object"==typeof t?r="?keys="+t.join("+"):n=t;var o="/app/config/get.json"+r;return e.get(o,n)},set:function(t,n){var o="/app/config/set.json?"+r.stringify(t);return e.post(o,null,n)}},data:{delete:function(t,n){var r="/app/data/delete.json?keys="+t.join("+");return e.post(r,null,n)},get:function(t,n){var r="";t&&"object"==typeof t?r="?keys="+t.join("+"):n=t;var o="/app/data/get.json"+r;return e.get(o,n)},set:function(t,n){var o="/app/data/set.json?"+r.stringify(t);return e.post(o,null,n)}}}}},function(t,e){t.exports=function(t,e){return{delete:function(t,n){return e.delete(`/bundled_items/${t}.json`,n)},show:function(t,n){return e.get(`/bundled_items/${t}.json`,n)}}}},function(t,e){t.exports=function(t,e){return{create:function(n,r){return e.post(`/people/${t.user.username}/bundles/create.json`,n,r)},delete:function(n,r){return e.delete(`/people/${t.user.username}/bundles/${n}.json`,r)},list:function(n,r,o){return e.get(`/people/${n||t.user.username}/bundles/list.json`,r,o)},show:function(n,r,o){return e.get(`/people/${n||t.user.username}/bundles/${r}.json`,o)},update:function(n,r,o){return e.post(`/people/${t.user.username}/bundles/${n}.json`,r,o)}}}},function(t,e){t.exports=function(t,e){return{add:function(t,n,r){return e.post(`/carts/${t}/add.json`,n,r)},create:function(t,n){return e.post("/carts/create.json",t,n)},externalCheckout:function(t,n,r){return e.post(`/carts/${t}/external_checkout.json`,n,r)},loveknitting:{externalCheckout:function(t,n,r){return e.post(`/carts/loveknitting/${t}/external_checkout.json`,n,r)}}}}},function(t,e){t.exports=function(t,e){return{create:function(t,n){return e.post("/comments/create.json",t,n)},delete:function(t,n){return e.delete(`/comments/${t}.json`,n)},list:function(n){return e.get(`/people/${t.user.username}/comments/list.json`,n)}}}},function(t,e){t.exports=function(t,e){return{list:function(t,n){return e.get("/deliveries/list.json",t,n)},renew:function(t,n,r){return e.post(`/deliveries/${t}/renew.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{createAttachment:function(t,n){return e.post("/extras/create_attachment.json",t,n)}}}},function(t,e){t.exports=function(t,e){return{addToBundle:function(n,r,o){return e.post(`/people/${t.user.username}/favorites/${n}/add_to_bundle.json`,r,o)},create:function(n,r){return e.post(`/people/${t.user.username}/favorites/create.json`,n,r)},delete:function(n,r){return e.deleteId(`/people/${t.user.username}/favorites/`,n,".json",r)},list:function(n,r,o){return e.get(`/people/${n||t.user.username}/favorites/list.json`,r,o)},removeFromBundle:function(n,r,o){return e.post(`/people/${t.user.username}/favorites/${n}/remove_from_bundle.json`,r,o)},show:function(n,r,o){return e.get(`/people/${n||t.user.username}/favorites/${r}.json`,o)},update:function(n,r,o){return e.post(`/people/${t.user.username}/favorites/${n}.json`,r,o)}}}},function(t,e){t.exports=function(t,e){return{create:function(n,r){return e.post(`/people/${t.user.username}/fiber/create.json`,n,r)},createPhoto:function(n,r,o){return e.post(`/people/${t.user.username}/fiber/${n}/create_photo.json`,r,o)},show:function(n,r,o){return e.get(`/people/${n||t.user.username}/fiber/${r}.json`,o)},update:function(n,r,o){return e.post(`/people/${t.user.username}/fiber/${n}.json`,r,o)}}}},function(t,e,n){var r=n(0);t.exports=function(t,e){return{show:function(t,n){return e.get(`/forum_posts/${t}.json`,n)},unread:function(t,n){return e.get("/forum_posts/unread.json?"+r.stringify(t),n)},update:function(t,n,r){return e.post(`/forum_posts/${t}.json`,n,r)},vote:function(t,n,r){return e.post(`/forum_posts/${t}/vote.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{sets:function(t){return e.get("/forums/sets.json",t)},topics:function(t,n,r){return e.get(`/forums/${t}/topics.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{activity:function(n,r,o){return e.get(`/people/${n||t.user.username}/friends/activity.json`,r,o)},create:function(n,r){return e.post(`/people/${t.user.username}/friends/create.json`,n,r)},destroy:function(n,r){return e.post(`/people/${t.user.username}/friends/${n}/destroy.json`,null,r)},list:function(n,r){return e.get(`/people/${n||t.user.username}/friends/list.json`,r)}}}},function(t,e){t.exports=function(t,e){var n={search:function(t,n){return e.ge("/groups/search.json",t,n)}};return n.groups=n.search,n}},function(t,e){t.exports=function(t,e){return{add:function(t,n,r){return e.post(`/in_store_sales/carts/${t}/add.json`,n,r)},addByPattern:function(t,n,r){return e.post(`/in_store_sales/carts/${t}/add_by_pattern.json`,n,r)},checkout:function(t,n,r){return e.post(`/in_store_sales/carts/${t}/checkout.json`,n,r)},create:function(t,n){return e.post("/in_store_sales/carts/create.json",t,n)},show:function(t,n){return e.get(`/in_store_sales/carts/${t}.json`,n)}}}},function(t,e){t.exports=function(t,e){return{search:function(n,r,o){return e.get(`/people/${n||t.user.username}/library/search.json`,r,o)}}}},function(t,e){t.exports=function(t,e){return{archive:function(t,n){return e.post(`/messages/${t}/archive.json`,null,n)},create:function(t,n){return e.post("/messages/create.json",t,n)},delete:function(t,n){return e.post(`/messages/${t}.json`,null,n)},list:function(t,n){return e.get("/messages/list.json",t,n)},markRead:function(t,n){return e.post(`/messages/${t}/mark_read.json`,null,n)},markUnread:function(t,n){return e.post(`/messages/${t}/mark_unread.json`,null,n)},reply:function(t,n,r){return e.post(`/messages/${t}/reply.json`,n,r)},show:function(t,n){return e.get(`/messages/${t}.json`,n)},unarchive:function(t,n){return e.post(`/messages/${t}/unarchive.json`,null,n)}}}},function(t,e){t.exports=function(t,e){return{list:function(n,r){return e.get(`/people/${n||t.user.username}/needles/list.json`,r)},sizes:function(t,n){return e.get("/needles/sizes.json",t,n)},types:function(t){return e.get("/needles/types.json",t)}}}},function(t,e){t.exports=function(t,e){return{create:function(t,n){return e.post("/packs/create.json",t,n)},delete:function(t,n){return e.delete(`/packs/${t}.json`,n)},show:function(t,n){return e.get(`/packs/${t}.json`,n)},update:function(t,n,r){return e.put(`/packs/${t}.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{show:function(t,n){return e.get(`/pages/${t}.json`,n)},update:function(t,n,r){return e.put(`/pages/${t}.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{patterns:function(t,n,r){return e.get(`/pattern_sources/${t}/patterns.json`,n,r)},search:function(t,n){return e.get("/pattern_sources/search.json",t,n)},show:function(t,n){return e.get(`/pattern_sources/${t}.json`,n)}}}},function(t,e){t.exports=function(t,e){return{comments:function(t,n,r){return e.get(`/patterns/${t}/comments.json`,n,r)},patterns:function(t,n){return e.get("/patterns.json",t,n)},projects:function(t,n,r){return e.get(`/patterns/${t}/projects.json`,n,r)},search:function(t,n){return e.get("/patterns/search.json",t,n)},show:function(t,n){return e.get(`/patterns/${t}.json`,n)}}}},function(t,e){t.exports=function(t,e){return{show:function(t,n){return e.get(`/people/${t}.json`,n)},update:function(t,n,r){return e.post(`/people/${t}.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{delete:function(t,n){return e.delete(`/photos/${t}.json`,n)},dimensions:function(t,n){return e.get("/photos/dimensions.json",t,n)},sizes:function(t,n){return e.get(`/photos/${t}/sizes.json`,n)},status:function(t,n){return e.get("photos/status.json",t,n)},update:function(t,n,r){return e.post(`/photos/${t}.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{generateDownloadLink:function(t,n){return e.post(`/product_attachments/${t}/generate_download_link.json`,{id:t},n)}}}},function(t,e){t.exports=function(t,e){return{loveknitting:{export:function(t,n){return e.get("/products/loveknitting/export.json",t,n)},updateStatus:function(t,n,r){return e.post(`/products/${t}/loveknitting/update_status.json`,n,r)}}}}},function(t,e){t.exports=function(t,e){return{comments:function(n,r,o,s){return e.get(`/projects/${n||t.user.username}/${r}/comments.json`,o,s)},crafts:function(t){return e.post("/projects/crafts.json",null,t)},create:function(n,r){return e.post(`/projects/${t.user.username}/create.json`,n,r)},createPhoto:function(n,r,o){return e.post(`/projects/${t.user.username}/${n}/create_photo.json`,r,o)},delete:function(t,n){return e.delete(`/projects/{username}/${t}.json`,n)},list:function(n,r,o){return e.get(`/projects/${n||t.user.username}/list.json`,r,o)},projectStatuses:function(t){return e.post("/projects/project_statuses.json",null,t)},reorderPhotos:function(n,r,o){return e.post(`/projects/${t.user.username}/${n}/reorder_photos.json`,r,o)},search:function(t,n){return e.get("/projects/search.json",t,n)},show:function(n,r,o,s){return e.get(`/projects/${n||t.user.username}/${r}.json`,o,s)},update:function(n,r,o){return e.post(`/projects/${t.user.username}/${n}.json`,r,o)}}}},function(t,e){t.exports=function(t,e){return{create:function(n,r){return e.post(`/people/${t.user.username}/queue/create.json`,n,r)},delete:function(n,r){return e.delete(`/people${t.user.username}/queue/${n}.json`,r)},list:function(n,r,o){return e.get(`/people/${n||t.user.username}/queue/list.json`,r,o)},order:function(n,r){return e.get(`/people/${n||t.user.username}/queue/order.json`,r)},reposition:function(n,r,o){return e.post(`/people/${t.user.username}/queue/${n}/reposition.json`,r,o)},show:function(n,r,o){return e.get(`/people/${n||t.user.username}/queue/${r}.json`,o)},update:function(n,r,o){return e.post(`/people/${t.user.username}/queue/${n}/update.json`,r,o)}}}},function(t,e){t.exports=function(t,e){return{list:function(t){return e.get("/saved_searches/list.json",t)}}}},function(t,e){t.exports=function(t,e){return{search:function(t,n){return e.get("/shops/search.json",t,n)},show:function(t,n,r){return e.get(`/shops/${t}.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{comments:function(n,r,o,s){return e.get(`/people/${n||t.user.username}/stash/${r}/comments.json`,o,s)},create:function(n,r){return e.post(`/people/${t.user.username}/stash/create.json`,n,r)},createPhoto:function(n,r,o){return e.post(`/people/${t.user.username}/stash/${n}/create_photo.json`,r,o)},delete:function(n,r){return e.delete(`/people/${t.user.username}/stash/${n}.json`,r)},list:function(n,r,o){return e.get(`/people/${n||t.user.username}/stash/list.json`,r,o)},reorderPhotos:function(n,r,o){return e.post(`/people/${t.user.username}/stash/${n}/reorder_photos.json`,r,o)},search:function(t,n){return e.get("/stash/search.json",t,n)},show:function(n,r,o){return e.get(`/people/${n||t.user.username}/stash/${r}.json`,o)},unified:{list:function(n,r,o){return e.get(`/people/${n||t.user.username}/stash/unified/list.json`,r,o)}},update:function(n,r,o){return e.post(`/people/${t.user.username}/stash/${n}.json`,r,o)}}}},function(t,e){t.exports=function(t,e){return{list:function(t){return e.get("/stores/list.json",t)},products:function(t,n){return e.get(`/stores/${t}/products.json`,n)},purchases:function(t,n){return e.get(`/stores/${t}/purchases.json`,n)}}}},function(t,e){t.exports=function(t,e){return{create:function(t,n){return e.post("/topics/create.json",t,n)},posts:function(t,n,r){return e.get(`/topics/${t}/posts.json`,n,r)},read:function(t,n,r){return e.post(`/topics/${t}/read.json`,n,r)},reply:function(t,n,r){return e.post(`/topics/${t}/reply.json`,n,r)},show:function(t,n){return e.get(`/topics/${t}.json`,n)},update:function(t,n,r){return e.post(`/topics/${t}.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{image:function(t,n){return e.post("/upload/image.json",t,n)},requestToken:function(t){return e.post("/upload/request_token.json",null,t)},status:function(t,n){return e.get("/upload/image/status.json",t,n)}}}},function(t,e){t.exports=function(t,e){return{create:function(t,n){return e.post("/volumes/create.json",t,n)},delete:function(t,n){return e.delete(`/volumes/${t}.json`,n)},show:function(t,n){return e.get(`/volumes/${t}.json`,n)},update:function(t,n,r){return e.get(`/volumes/${t}/update.json`,n,r)}}}},function(t,e){t.exports=function(t,e){return{search:function(t,n){return e.get("/yarns/search.json",t,n)},show:function(t,n){return e.get(`/yarns/${t}.json`,n)},yarns:function(t,n){return e.get("/yarns.json",t,n)}}}}])});