Skip to content

Commit c82150c

Browse files
authored
Merge pull request #65 from privy-open-source/feat/axios-1.x
release: `1.0.0`
2 parents f8937e7 + e8c37a7 commit c82150c

39 files changed

Lines changed: 3989 additions & 6729 deletions

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ out
8989

9090
# Nuxt.js build / generate output
9191
.nuxt
92+
.output
9293
dist
9394

9495
# Gatsby files

.github/workflows/ci.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,26 @@ on:
1111
merge_group:
1212
types: [checks_requested]
1313

14+
env:
15+
NODE_VERSION: 20
16+
1417
jobs:
1518
analyze:
16-
runs-on: ${{ matrix.os }}
19+
runs-on: ubuntu-latest
1720

1821
permissions:
1922
actions: read
2023
contents: read
2124
security-events: write
2225

23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
os:
27-
- ubuntu-latest
28-
language:
29-
- javascript
30-
3126
steps:
3227
- name: Git Checkout
3328
uses: actions/checkout@v3
3429

3530
- name: Initialize CodeQL
3631
uses: github/codeql-action/init@v2
3732
with:
38-
languages: ${{ matrix.language }}
33+
languages: javascript
3934

4035
- name: Autobuild
4136
uses: github/codeql-action/autobuild@v2
@@ -44,15 +39,7 @@ jobs:
4439
uses: github/codeql-action/analyze@v2
4540

4641
build:
47-
runs-on: ${{ matrix.os }}
48-
49-
strategy:
50-
fail-fast: false
51-
matrix:
52-
os:
53-
- ubuntu-latest
54-
node-version:
55-
- 18
42+
runs-on: ubuntu-latest
5643

5744
steps:
5845
- name: Git Checkout
@@ -73,10 +60,10 @@ jobs:
7360
restore-keys: |
7461
${{ runner.os }}-yarn-
7562
76-
- name: Use Node.js ${{ matrix.node-version }}
63+
- name: Use Node.js ${{ env.NODE_VERSION }}
7764
uses: actions/setup-node@v4
7865
with:
79-
node-version: ${{ matrix.node-version }}
66+
node-version: ${{ env.NODE_VERSION }}
8067
cache: "yarn"
8168

8269
- name: Install Deps

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ out
8989

9090
# Nuxt.js build / generate output
9191
.nuxt
92+
.output
9293
dist
9394

9495
# Gatsby files
@@ -128,3 +129,5 @@ dist
128129
.yarn/build-state.yml
129130
.yarn/install-state.gz
130131
.pnp.*
132+
133+
.clinic/

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

.yarn/releases/yarn-3.8.3.cjs

Lines changed: 0 additions & 875 deletions
This file was deleted.

.yarn/releases/yarn-4.4.0.cjs

Lines changed: 0 additions & 925 deletions
This file was deleted.

.yarn/releases/yarn-4.5.3.cjs

Lines changed: 934 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ enableGlobalCache: false
44

55
nodeLinker: node-modules
66

7-
yarnPath: .yarn/releases/yarn-4.4.0.cjs
7+
yarnPath: .yarn/releases/yarn-4.5.3.cjs

README.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Find and replace all on all files (CMD+SHIFT+F):
2424

2525
<!-- Highlight some of the features your module provide here -->
2626
- ✅ Using Fetch instead of XHR
27-
- ✅ Built-in adapter for Dedupe, and Priority Queue request.
27+
- ✅ Built-in adapter for Retry, Dedupe, and Priority Queue request.
2828
- ✅ Composable hook for Axios interceptors.
2929

3030
## Compabilities
@@ -133,26 +133,80 @@ onResponseError(async (error) => {
133133

134134
## Queue
135135

136-
All request per instance will be add into queue before sent with priority `1`.
136+
All request per instance will be add into queue before sent with priority MEDIUM (`20`).
137137
If you want to send your request first before the others, you can set using option `priority`. The higher priority will run first.
138138

139139
```ts
140+
import { QueuePriority } from '@privyid/nuapi/core'
141+
140142
useApi().get('/document/load', {
141-
priority: 2,
143+
// Using presets
144+
priority: QueuePriority.HIGH,
145+
// Or using number
146+
priority: 50,
142147
})
143148
```
144149

145150
## Dedupe
146151

147152
Sometime, you want to cancel request with same endpoint like when you working with searching or filter.
148153

149-
NuAPI has built in function for this case. Just set `requestId`, multiple sent request with same id will cancel last request before.
154+
NuAPI has built in function for this case. Just set `requestkey`, multiple sent request with same id will cancel last request before.
150155

151156
```ts
152157
useApi().get('/document/load', {
153-
requestId: 'document-load',
158+
requestkey: 'document-load',
154159
})
155160
```
161+
162+
### Cancel Manually
163+
164+
Cancel spesific request by `requestKey` using `.cancel()`
165+
166+
```ts
167+
useApi().cancel('document-load')
168+
```
169+
170+
Or cancel all requests that have `requestKey` using `.cancelAll()`
171+
172+
```ts
173+
useApi().cancelAll()
174+
```
175+
176+
## Retry
177+
178+
NuAPI automatically retries request when got an error with status code:
179+
180+
- 408 - Request Timeout
181+
- 409 - Conflict
182+
- 425 - Too Early
183+
- 429 - Too Many Requests
184+
- 500 - Internal Server Error
185+
- 502 - Bad Gateway
186+
- 503 - Service Unavailable
187+
- 504 - Gateway Timeout
188+
189+
By default will retries `3` times (except for `PATCH`, `POST`, `PUT`, `DELETE`) can be changed using option `retry`.
190+
191+
```ts
192+
useApi().get('/document/load', {
193+
retry: 5,
194+
})
195+
```
196+
197+
### Customize Retry Condition
198+
199+
You can customize when request should retries using `retryOn`
200+
201+
```ts
202+
useApi().get('/document/load', {
203+
retryOn (error) {
204+
return getCode(error) === 423
205+
&& error.config.retryCount < 3
206+
},
207+
})
208+
```
209+
156210
## API
157211

158212
👉 You can learn more about usage in [JSDocs Documentation](https://www.jsdocs.io/package/@privyid/nuapi).

msw.setup.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const server = setupServer(
1919
await delay(2)
2020
}),
2121

22+
http.all(`${BASE_URL}/api/echo`, async ({ request }) => {
23+
return HttpResponse.json({
24+
method : request.method,
25+
headers: request.headers,
26+
})
27+
}),
28+
2229
http.get(`${BASE_URL}/api/ping`, () => {
2330
return HttpResponse.json({ message: 'Pong' })
2431
}),
@@ -55,8 +62,20 @@ const server = setupServer(
5562
}, { status: 422 })
5663
}),
5764

58-
http.get(`${BASE_URL}/api/error/500`, () => {
59-
return new HttpResponse(undefined, { status: 500 })
65+
http.all(`${BASE_URL}/api/error/500`, () => {
66+
return HttpResponse.json({}, { status: 500 })
67+
}),
68+
69+
http.get(`${BASE_URL}/api/error/unstable`, async function * () {
70+
let count = 0
71+
72+
while (count < 2) {
73+
yield HttpResponse.json({ data: { count } }, { status: 500 })
74+
75+
count++
76+
}
77+
78+
return HttpResponse.json({ message: 'Pong', data: { count } })
6079
}),
6180
)
6281

0 commit comments

Comments
 (0)