@quiltt/core 3.5.5 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -10
- package/README.md +1 -1
- package/dist/{SubscriptionLink-client-B5Tmyqw7.js → SubscriptionLink-client-Bf6n9gzT.js} +70 -61
- package/dist/{index-client-BY-d8Msy.js → index-client-C87sSU05.js} +1 -1
- package/dist/index.d.ts +190 -179
- package/dist/index.js +122 -86
- package/package.json +13 -14
- package/src/api/graphql/links/ActionCableLink.ts +1 -1
- package/src/api/graphql/links/AuthLink.ts +1 -1
- package/src/api/graphql/links/BatchHttpLink.ts +4 -2
- package/src/api/graphql/links/ErrorLink.ts +1 -1
- package/src/api/graphql/links/HttpLink.ts +4 -2
- package/src/api/rest/{AuthAPI.ts → auth.ts} +39 -26
- package/src/api/rest/fetchWithRetry.ts +73 -0
- package/src/api/rest/index.ts +1 -1
- package/src/configuration.ts +33 -19
- package/src/index.ts +2 -2
- package/src/{Storage → storage}/Local.ts +0 -2
- package/src/{Storage → storage}/Memory.ts +0 -2
- package/src/{Storage/index.ts → storage/Storage.ts} +0 -3
- package/src/storage/index.ts +3 -0
- package/src/api/rest/axios.ts +0 -52
package/src/index.ts
CHANGED
package/src/api/rest/axios.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { AxiosRequestConfig as RequestConfig } from 'axios'
|
|
2
|
-
import Axios from 'axios'
|
|
3
|
-
|
|
4
|
-
export type { AxiosResponse } from 'axios'
|
|
5
|
-
export type AxiosRequestConfig<D = any> = RequestConfig<D> & {
|
|
6
|
-
retry: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const RETRY_DELAY = 150 // ms
|
|
10
|
-
const RETRIES = 10 // 150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500 = 8.250s
|
|
11
|
-
|
|
12
|
-
// Create an axios singleton for Quiltt, to prevent mutating other instances
|
|
13
|
-
const axios = Axios.create()
|
|
14
|
-
|
|
15
|
-
// Example: axios.get(url, { retry: true })
|
|
16
|
-
axios.interceptors.response.use(undefined, (error) => {
|
|
17
|
-
const { config, message, response } = error
|
|
18
|
-
const messageLower = message.toLowerCase()
|
|
19
|
-
|
|
20
|
-
if (!config || !config.retry) {
|
|
21
|
-
return Promise.reject(error)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Retry Network timeout, Network errors, and Too Many Requests
|
|
25
|
-
if (
|
|
26
|
-
!(
|
|
27
|
-
messageLower.includes('timeout') ||
|
|
28
|
-
messageLower.includes('network error') ||
|
|
29
|
-
response?.status === 429
|
|
30
|
-
)
|
|
31
|
-
) {
|
|
32
|
-
return Promise.reject(error)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (config.retriesRemaining === undefined) {
|
|
36
|
-
config.retriesRemaining = RETRIES - 1
|
|
37
|
-
} else if (config.retriesRemaining === 1) {
|
|
38
|
-
return Promise.reject(error)
|
|
39
|
-
} else {
|
|
40
|
-
config.retriesRemaining -= 1
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const delay = new Promise<void>((resolve) => {
|
|
44
|
-
setTimeout(() => resolve(), RETRY_DELAY * (RETRIES - config.retriesRemaining))
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
return delay.then(() => axios(config))
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
export { axios }
|
|
51
|
-
|
|
52
|
-
export default axios
|