Comparing version 1.0.10 to 1.0.11
@@ -115,2 +115,16 @@ 'use strict'; | ||
}, { | ||
key: 'setCookies', | ||
value: function setCookies(cookies) { | ||
this._cookies = cookies; | ||
var expires = cookies.find(function (cookie) { | ||
return cookie.includes('expires='); | ||
}).split('; ').find(function (cookie) { | ||
return cookie.startsWith('expires='); | ||
}); | ||
if (expires) { | ||
this._expires = new Date(expires.replace('expires=', '')); | ||
} | ||
} | ||
}, { | ||
key: 'handleResponse', | ||
@@ -124,3 +138,3 @@ value: function handleResponse(_ref) { | ||
if (options.saveCookies) { | ||
this._cookies = response.headers['set-cookie']; | ||
this.setCookies(response.headers['set-cookie']); | ||
} | ||
@@ -149,2 +163,7 @@ var handler = new responseHandlerClass(rawData); | ||
} | ||
}, { | ||
key: 'expires', | ||
get: function get() { | ||
return this._expires; | ||
} | ||
}]); | ||
@@ -151,0 +170,0 @@ |
{ | ||
"name": "amocrm-js", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "JS Library for AmoCRM", | ||
@@ -5,0 +5,0 @@ "main": "dist/AmoCRM.js", |
@@ -83,3 +83,3 @@ import AmoCRM from '../src/AmoCRM'; | ||
setTimeout(() => !checked && disconnected && done(), 2000); | ||
setTimeout(() => !checked && disconnected && done(), 2000 ); | ||
}); | ||
@@ -249,2 +249,19 @@ | ||
}); | ||
it( 'many requests check', async done => { | ||
const { domain, auth: { hash, login } } = config, | ||
crm = new AmoCRM({ | ||
domain, | ||
auth: { | ||
hash, login | ||
} | ||
}); | ||
await crm.connect(); | ||
for (let i = 0; i < 10; i++) { | ||
await crm.request.get( '/api/v2/account' ); | ||
} | ||
done(); | ||
}); | ||
}); |
@@ -29,2 +29,6 @@ 'use strict'; | ||
get expires() { | ||
return this._expires; | ||
} | ||
request( url, data = {}, method = 'GET', options = {}) { | ||
@@ -67,6 +71,17 @@ const encodedData = this.encodeData( url, data, method, options ), | ||
setCookies( cookies ) { | ||
this._cookies = cookies; | ||
const expires = cookies.find( cookie => cookie.includes( 'expires=' )) | ||
.split( '; ' ) | ||
.find( cookie => cookie.startsWith( 'expires=' )); | ||
if ( expires ) { | ||
this._expires = new Date( expires.replace( 'expires=', '' )); | ||
} | ||
} | ||
handleResponse({ rawData, response }, options = {}) { | ||
const { responseHandlerClass } = this.constructor; | ||
if ( options.saveCookies ) { | ||
this._cookies = response.headers[ 'set-cookie' ]; | ||
this.setCookies( response.headers[ 'set-cookie' ]) | ||
} | ||
@@ -73,0 +88,0 @@ const handler = new responseHandlerClass( rawData ); |
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
3733
181250
117