-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from privy-open-source/feat/axios-1.x
feat: fetch adapter
- Loading branch information
Showing
24 changed files
with
7,029 additions
and
5,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false | ||
|
||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.8.3.cjs | ||
yarnPath: .yarn/releases/yarn-4.1.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
delay, | ||
http, | ||
HttpResponse, | ||
} from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import { | ||
afterAll, | ||
afterEach, | ||
beforeAll, | ||
beforeEach, | ||
} from 'vitest' | ||
import { setApi, createApi } from './src/core' | ||
|
||
const BASE_URL = 'http://localhost:3000' | ||
|
||
const server = setupServer( | ||
http.all('*', async () => { | ||
await delay(2) | ||
}), | ||
|
||
http.get(`${BASE_URL}/api/ping`, () => { | ||
return HttpResponse.json({ message: 'Pong' }) | ||
}), | ||
|
||
http.get(`${BASE_URL}/v1/api/ping`, () => { | ||
return HttpResponse.json({ message: 'Pong', data: { version: 'v1' } }) | ||
}), | ||
|
||
http.get(`${BASE_URL}/v2/api/ping`, () => { | ||
return HttpResponse.json({ message: 'Pong', data: { version: 'v2' } }) | ||
}), | ||
|
||
http.get(`${BASE_URL}/api/user`, () => { | ||
return HttpResponse.json({ data: 'data-user' }) | ||
}), | ||
|
||
http.get(`${BASE_URL}/api/error/404`, () => { | ||
return HttpResponse.json({ | ||
code : 404, | ||
details: [], | ||
}, { status: 404 }) | ||
}), | ||
|
||
http.get(`${BASE_URL}/api/error/422`, () => { | ||
return HttpResponse.json({ | ||
code : 422, | ||
message: 'Validation Error', | ||
details: [ | ||
{ | ||
type_url: 'type_url', | ||
value : 'base64string', | ||
}, | ||
], | ||
}, { status: 422 }) | ||
}), | ||
|
||
http.get(`${BASE_URL}/api/error/500`, () => { | ||
return new HttpResponse(undefined, { status: 500 }) | ||
}), | ||
) | ||
|
||
beforeAll(() => { | ||
server.listen() | ||
}) | ||
|
||
beforeEach(() => { | ||
setApi(createApi({ baseURL: BASE_URL })) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
||
process.env.BASE_URL = BASE_URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { createLazyton } from '@privyid/nuapi/core' | ||
import { | ||
type AxiosRequestConfig, | ||
createLazyton, | ||
} from '@privyid/nuapi/core' | ||
|
||
const useApi = createLazyton({ prefixURL: '/api' }) | ||
|
||
export async function getUser () { | ||
return await useApi().get('/users') | ||
export async function getUser (config?: AxiosRequestConfig) { | ||
return await useApi().get('/users', config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,62 @@ | |
<button @click="refresh()"> | ||
Reload | ||
</button> | ||
<button | ||
:disabled="!file" | ||
@click="register()"> | ||
Register | ||
</button> | ||
<input | ||
type="file" | ||
accept="image/*" | ||
@change="onChange"> | ||
<img :src="preview"> | ||
<pre v-if="pending">Loading...</pre> | ||
<pre v-else>{{ data }}</pre> | ||
<pre v-if="error">{{ error }}</pre> | ||
</template> | ||
|
||
<script setup> | ||
import { useApi } from '@privyid/nuapi/core' | ||
<script setup lang="ts"> | ||
import { getUser } from '~/api/coba' | ||
import { useAsyncData } from '#app' | ||
import { ref, watchEffect } from 'vue-demi' | ||
import { useApi } from '@privyid/nuapi/core' | ||
const { data, refresh, pending } = await useAsyncData('users', async () => { | ||
const { data } = await useApi().get('/api/users') | ||
const file = ref() | ||
const preview = ref() | ||
const { data, refresh, pending, error } = await useAsyncData('users', async () => { | ||
const { data } = await getUser({ requestId: 'get-user' }) | ||
return data | ||
}, | ||
) | ||
}) | ||
function onChange (event: InputEvent) { | ||
const target = event.target as HTMLInputElement | ||
const files = target.files | ||
if (files) | ||
file.value = files[0] | ||
} | ||
function register () { | ||
const form = new FormData() | ||
form.append('email', '[email protected]') | ||
form.append('password', 'pistol') | ||
useApi().post('/api/regi', form) | ||
} | ||
watchEffect((onCleanup) => { | ||
if (file.value) { | ||
const url = URL.createObjectURL(file.value) | ||
onCleanup(() => { | ||
URL.revokeObjectURL(url) | ||
}) | ||
preview.value = url | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.