@clevercloud/client
Advanced tools
Comparing version 8.0.3 to 8.1.0
@@ -26,2 +26,3 @@ "use strict"; | ||
* @param {string} options.appId | ||
* @param {number} options.connectionTimeout | ||
* @param {object} options.retryConfiguration | ||
@@ -48,5 +49,6 @@ * @param {boolean} options.retryConfiguration.enabled | ||
retryConfiguration, | ||
connectionTimeout, | ||
...options | ||
}) { | ||
super(apiHost, tokens, retryConfiguration ?? {}); | ||
super(apiHost, tokens, retryConfiguration ?? {}, connectionTimeout); | ||
this._ownerId = ownerId; | ||
@@ -53,0 +55,0 @@ this._appId = appId; |
@@ -24,3 +24,3 @@ "use strict"; | ||
const CONNECTION_TIMEOUT_MS = 5000; | ||
const NETWORK_ERROR_CODES = ['EAI_AGAIN', 'ECONNREFUSED', 'ECONNRESET', 'EPIPE', 'ETIMEDOUT', 'UND_ERR_SOCKET']; | ||
const NETWORK_ERROR_CODES = ['EAI_AGAIN', 'ENOTFOUND', 'ECONNREFUSED', 'ECONNRESET', 'EPIPE', 'ETIMEDOUT', 'UND_ERR_SOCKET']; | ||
/** | ||
@@ -42,2 +42,3 @@ * CleverCloud specificities over an SSE | ||
* @param {string} tokens.API_OAUTH_TOKEN_SECRET | ||
* @param {number} connectionTimeout | ||
* @param {object} retryConfiguration | ||
@@ -49,3 +50,3 @@ * @param {boolean} retryConfiguration.enabled | ||
*/ | ||
constructor(apiHost, tokens, retryConfiguration = {}) { | ||
constructor(apiHost, tokens, retryConfiguration = {}, connectionTimeout) { | ||
super(); | ||
@@ -63,3 +64,4 @@ this._apiHost = apiHost; | ||
this._retryTimeoutId = null; | ||
this._retryCount = 0; | ||
this.retryCount = 0; | ||
this._connectionTimeout = connectionTimeout ?? CONNECTION_TIMEOUT_MS; | ||
this.state = 'init'; | ||
@@ -180,3 +182,3 @@ } | ||
if (this._retryCount >= this._retry.maxRetryCount) { | ||
if (this.retryCount >= this._retry.maxRetryCount) { | ||
return false; | ||
@@ -225,3 +227,3 @@ } | ||
this._lastContact = new Date(); | ||
this._retryCount = 0; | ||
this.retryCount = 0; | ||
this._heartbeatIntervalId = setInterval(() => { | ||
@@ -325,7 +327,5 @@ const now = new Date(); | ||
this._cleanup(); // TODO List some well know NetworkError (node and browser) | ||
this._cleanup(); | ||
const errorCode = error?.cause?.code ?? error.code; | ||
const wrappedError = NETWORK_ERROR_CODES.includes(errorCode) ? new NetworkError('Failed to establish/maintain the connection with the server', { | ||
const wrappedError = isNetworkError(error) ? new NetworkError('Failed to establish/maintain the connection with the server', { | ||
cause: error | ||
@@ -339,4 +339,4 @@ }) : error; | ||
}); | ||
this._retryCount++; | ||
const exponentialBackoffDelay = this._retry.initRetryTimeout * this._retry.backoffFactor ** this._retryCount; | ||
this.retryCount++; | ||
const exponentialBackoffDelay = this._retry.initRetryTimeout * this._retry.backoffFactor ** this.retryCount; | ||
this._retryTimeoutId = setTimeout(() => { | ||
@@ -370,2 +370,22 @@ this._start(); | ||
function isNetworkError(error) { | ||
const errorCode = error?.cause?.code ?? error.code; | ||
if (NETWORK_ERROR_CODES.includes(errorCode)) { | ||
return true; | ||
} | ||
if (error.name === 'TypeError') { | ||
if (error.message === 'Failed to fetch') { | ||
return true; | ||
} | ||
if (error.message.startsWith('NetworkError')) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
class NetworkError extends Error {} | ||
@@ -372,0 +392,0 @@ |
@@ -35,3 +35,4 @@ "use strict"; | ||
signal.addEventListener('abort', () => { | ||
reader.cancel(signal.reason); | ||
reader.cancel(signal.reason) // Firefox doesn't like when we cancel a reader that is already closed but we can ignore this | ||
.catch(() => null); | ||
}, { | ||
@@ -38,0 +39,0 @@ once: true |
@@ -17,2 +17,3 @@ import CleverCloudSse from './clever-cloud-sse.js'; | ||
* @param {string} options.appId | ||
* @param {number} options.connectionTimeout | ||
* @param {object} options.retryConfiguration | ||
@@ -33,4 +34,4 @@ * @param {boolean} options.retryConfiguration.enabled | ||
*/ | ||
constructor ({ apiHost, tokens, ownerId, appId, retryConfiguration, ...options }) { | ||
super(apiHost, tokens, retryConfiguration ?? {}); | ||
constructor ({ apiHost, tokens, ownerId, appId, retryConfiguration, connectionTimeout, ...options }) { | ||
super(apiHost, tokens, retryConfiguration ?? {}, connectionTimeout); | ||
this._ownerId = ownerId; | ||
@@ -37,0 +38,0 @@ this._appId = appId; |
@@ -16,3 +16,3 @@ import { CustomEventTarget } from './custom-event-target.js'; | ||
const NETWORK_ERROR_CODES = ['EAI_AGAIN', 'ECONNREFUSED', 'ECONNRESET', 'EPIPE', 'ETIMEDOUT', 'UND_ERR_SOCKET']; | ||
const NETWORK_ERROR_CODES = ['EAI_AGAIN', 'ENOTFOUND', 'ECONNREFUSED', 'ECONNRESET', 'EPIPE', 'ETIMEDOUT', 'UND_ERR_SOCKET']; | ||
@@ -34,2 +34,3 @@ /** | ||
* @param {string} tokens.API_OAUTH_TOKEN_SECRET | ||
* @param {number} connectionTimeout | ||
* @param {object} retryConfiguration | ||
@@ -41,3 +42,3 @@ * @param {boolean} retryConfiguration.enabled | ||
*/ | ||
constructor (apiHost, tokens, retryConfiguration = {}) { | ||
constructor (apiHost, tokens, retryConfiguration = {}, connectionTimeout) { | ||
super(); | ||
@@ -53,3 +54,4 @@ this._apiHost = apiHost; | ||
this._retryTimeoutId = null; | ||
this._retryCount = 0; | ||
this.retryCount = 0; | ||
this._connectionTimeout = connectionTimeout ?? CONNECTION_TIMEOUT_MS; | ||
this.state = 'init'; | ||
@@ -164,3 +166,3 @@ } | ||
if (this._retryCount >= this._retry.maxRetryCount) { | ||
if (this.retryCount >= this._retry.maxRetryCount) { | ||
return false; | ||
@@ -213,3 +215,3 @@ } | ||
this._lastContact = new Date(); | ||
this._retryCount = 0; | ||
this.retryCount = 0; | ||
@@ -301,5 +303,3 @@ this._heartbeatIntervalId = setInterval(() => { | ||
// TODO List some well know NetworkError (node and browser) | ||
const errorCode = error?.cause?.code ?? error.code; | ||
const wrappedError = NETWORK_ERROR_CODES.includes(errorCode) | ||
const wrappedError = isNetworkError(error) | ||
? new NetworkError('Failed to establish/maintain the connection with the server', { cause: error }) | ||
@@ -312,4 +312,4 @@ : error; | ||
this._retryCount++; | ||
const exponentialBackoffDelay = this._retry.initRetryTimeout * (this._retry.backoffFactor ** this._retryCount); | ||
this.retryCount++; | ||
const exponentialBackoffDelay = this._retry.initRetryTimeout * (this._retry.backoffFactor ** this.retryCount); | ||
@@ -339,2 +339,21 @@ this._retryTimeoutId = setTimeout(() => { | ||
function isNetworkError (error) { | ||
const errorCode = error?.cause?.code ?? error.code; | ||
if (NETWORK_ERROR_CODES.includes(errorCode)) { | ||
return true; | ||
} | ||
if (error.name === 'TypeError') { | ||
if (error.message === 'Failed to fetch') { | ||
return true; | ||
} | ||
if (error.message.startsWith('NetworkError')) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
export class NetworkError extends Error { | ||
@@ -341,0 +360,0 @@ } |
@@ -30,3 +30,5 @@ // This code is adapted from https://github.com/Azure/fetch-event-source | ||
signal.addEventListener('abort', () => { | ||
reader.cancel(signal.reason); | ||
reader.cancel(signal.reason) | ||
// Firefox doesn't like when we cancel a reader that is already closed but we can ignore this | ||
.catch(() => null); | ||
}, { once: true }); | ||
@@ -33,0 +35,0 @@ |
{ | ||
"name": "@clevercloud/client", | ||
"version": "8.0.3", | ||
"version": "8.1.0", | ||
"description": "JavaScript REST client and utils for Clever Cloud's API", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/CleverCloud/clever-client.js", |
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
601261
18478
4