@crowdin/crowdin-api-client
Advanced tools
Comparing version 1.5.7 to 1.6.0
@@ -8,2 +8,8 @@ # Change Log | ||
## [1.6.0] | ||
### Added | ||
- Added retry mechanism | ||
## [1.5.0] | ||
@@ -10,0 +16,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { RetryConfig, RetryService } from './internal/retry'; | ||
export interface RequestConfig { | ||
@@ -26,2 +27,3 @@ headers?: any; | ||
integrationUserAgent?: string; | ||
retryConfig?: RetryConfig; | ||
} | ||
@@ -97,2 +99,3 @@ export interface ResponseList<T> { | ||
readonly config: ClientConfig | undefined; | ||
readonly retryService: RetryService; | ||
/** | ||
@@ -99,0 +102,0 @@ * @param credentials credentials |
@@ -5,2 +5,3 @@ "use strict"; | ||
const fetchClient_1 = require("./internal/fetch/fetchClient"); | ||
const retry_1 = require("./internal/retry"); | ||
var HttpClientType; | ||
@@ -39,2 +40,14 @@ (function (HttpClientType) { | ||
} | ||
let retryConfig; | ||
if (!!config && !!config.retryConfig) { | ||
retryConfig = config.retryConfig; | ||
} | ||
else { | ||
retryConfig = { | ||
waitInterval: 0, | ||
retries: 0, | ||
conditions: [], | ||
}; | ||
} | ||
this.retryService = new retry_1.RetryService(retryConfig); | ||
this.config = config; | ||
@@ -85,18 +98,18 @@ } | ||
get(url, config) { | ||
return this.httpClient.get(url, config); | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.get(url, config)); | ||
} | ||
delete(url, config) { | ||
return this.httpClient.delete(url, config); | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.delete(url, config)); | ||
} | ||
head(url, config) { | ||
return this.httpClient.head(url, config); | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.head(url, config)); | ||
} | ||
post(url, data, config) { | ||
return this.httpClient.post(url, data, config); | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.post(url, data, config)); | ||
} | ||
put(url, data, config) { | ||
return this.httpClient.put(url, data, config); | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.put(url, data, config)); | ||
} | ||
patch(url, data, config) { | ||
return this.httpClient.patch(url, data, config); | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.patch(url, data, config)); | ||
} | ||
@@ -103,0 +116,0 @@ } |
{ | ||
"name": "@crowdin/crowdin-api-client", | ||
"version": "1.5.7", | ||
"version": "1.6.0", | ||
"description": "JavaScript library for Crowdin API v2.", | ||
@@ -5,0 +5,0 @@ "main": "out/index.js", |
@@ -163,2 +163,24 @@ [<p align='center'><img src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' data-canonical-src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' width='200' height='200' align='center'/></p>](https://crowdin.com) | ||
### Retry configuration | ||
There is a possibility to configure client invoke http calls with retry mechanism. | ||
```typescript | ||
import { ProjectsGroups, HttpClientType } from '@crowdin/crowdin-api-client'; | ||
const projectsGroupsApi = new ProjectsGroups(credentials, { | ||
retryConfig: { | ||
retries: 2, // amount of retries (gte 1) | ||
waitInterval: 100, // wait interval in ms between retries | ||
conditions: [ // array of conditions which will check if retry should not be applied | ||
{ | ||
test(error) { | ||
return error.code === 40 | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
``` | ||
## Contribution | ||
@@ -165,0 +187,0 @@ We are happy to accept contributions to the Crowdin JavaScript client. To contribute please do the following: |
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
165314
50
4095
210