@vesperjs/nuxt 0.3.1 → 0.3.3
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/app/composables/backend/api/use-mutation-api.ts +11 -3
- package/app/composables/backend/api/use-query-api.ts +3 -2
- package/app/composables/backend/index.ts +2 -2
- package/app/composables/backend/{use-alert.ts → use-api-error.ts} +9 -6
- package/app/composables/index.ts +2 -2
- package/package.json +7 -7
|
@@ -9,6 +9,7 @@ interface MutationAPIOptions {
|
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
body?: Record<string, any> | FormData
|
|
11
11
|
token?: string | null
|
|
12
|
+
baseURL?: string | null
|
|
12
13
|
onRequestError?: ({ error }: { error: Error }) => void
|
|
13
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
15
|
onResponseError?: ({ response }: { response: FetchResponse<any> }) => void
|
|
@@ -17,7 +18,14 @@ interface MutationAPIOptions {
|
|
|
17
18
|
// eslint-disable-next-line
|
|
18
19
|
export const useMutationApi = async function <T = unknown, E = any>(
|
|
19
20
|
url: string,
|
|
20
|
-
{
|
|
21
|
+
{
|
|
22
|
+
method,
|
|
23
|
+
body = {},
|
|
24
|
+
token = null,
|
|
25
|
+
baseURL = null,
|
|
26
|
+
onRequestError,
|
|
27
|
+
onResponseError,
|
|
28
|
+
}: MutationAPIOptions,
|
|
21
29
|
): Promise<{
|
|
22
30
|
token: string | null | undefined
|
|
23
31
|
data: T | undefined
|
|
@@ -25,7 +33,7 @@ export const useMutationApi = async function <T = unknown, E = any>(
|
|
|
25
33
|
pending: boolean
|
|
26
34
|
}> {
|
|
27
35
|
const { commonHeaders } = useHttpHeaders()
|
|
28
|
-
const { baseURL } = useApiConstants()
|
|
36
|
+
const { baseURL: baseUrl } = useApiConstants()
|
|
29
37
|
|
|
30
38
|
const headers: Record<string, string> = commonHeaders.value
|
|
31
39
|
|
|
@@ -36,7 +44,7 @@ export const useMutationApi = async function <T = unknown, E = any>(
|
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
const options: FetchOptions<'json'> = {
|
|
39
|
-
baseURL: baseURL.value,
|
|
47
|
+
baseURL: baseURL ?? baseUrl.value,
|
|
40
48
|
headers,
|
|
41
49
|
method,
|
|
42
50
|
}
|
|
@@ -17,6 +17,7 @@ export type QueryAPIOptions = {
|
|
|
17
17
|
key?: MaybeRefOrGetter<string>
|
|
18
18
|
query?: SearchParams
|
|
19
19
|
token?: string | null
|
|
20
|
+
baseURL?: string | null
|
|
20
21
|
signal?: AbortSignal
|
|
21
22
|
onRequestError?: ({ error }: { error: Error }) => void
|
|
22
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -33,7 +34,7 @@ export const useQueryApi = async function <T = unknown, E = any>(
|
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
35
|
const { $api } = useNuxtApp() as any
|
|
35
36
|
const { commonHeaders } = useHttpHeaders()
|
|
36
|
-
const { baseURL } = useApiConstants()
|
|
37
|
+
const { baseURL: baseUrl } = useApiConstants()
|
|
37
38
|
|
|
38
39
|
const key = options?.key ?? url
|
|
39
40
|
|
|
@@ -50,7 +51,7 @@ export const useQueryApi = async function <T = unknown, E = any>(
|
|
|
50
51
|
|
|
51
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
53
|
const getOptions: FetchOptions<'json', any> = {
|
|
53
|
-
baseURL: baseURL.value,
|
|
54
|
+
baseURL: options?.baseURL ?? baseUrl.value,
|
|
54
55
|
method: 'get',
|
|
55
56
|
query: options?.query ?? {},
|
|
56
57
|
headers,
|
|
@@ -2,7 +2,7 @@ export type { QueryAPIOptions } from './api'
|
|
|
2
2
|
|
|
3
3
|
export { createFetch, createRequestFetch, useOFetch, useMutationApi, useQueryApi } from './api'
|
|
4
4
|
|
|
5
|
-
export { useAlert } from './use-
|
|
5
|
+
export { useApiError, useAlert } from './use-api-error'
|
|
6
6
|
export { useExternalErrors } from './error'
|
|
7
7
|
|
|
8
|
-
export type { UseAlertType } from './use-
|
|
8
|
+
export type { UseApiErrorType, UseAlertType } from './use-api-error'
|
|
@@ -15,20 +15,20 @@ import type {
|
|
|
15
15
|
|
|
16
16
|
import { useBackendErrorInfo } from './error'
|
|
17
17
|
|
|
18
|
-
interface
|
|
18
|
+
interface UseApiErrorOptions {
|
|
19
19
|
flash: Ref<Flash>
|
|
20
|
-
caller?:
|
|
20
|
+
caller?: UseApiErrorCallerType
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
interface
|
|
23
|
+
interface UseApiErrorCallerType {
|
|
24
24
|
externalErrors?: Ref<ErrorMessages<string>>
|
|
25
25
|
clearAccount?: () => void
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export const
|
|
28
|
+
export const useApiError = function <BER extends object = BackendErrorResource>({
|
|
29
29
|
flash,
|
|
30
30
|
caller,
|
|
31
|
-
}:
|
|
31
|
+
}: UseApiErrorOptions): {
|
|
32
32
|
backendErrorInfo: Ref<BackendErrorInfo<BER>, BER>
|
|
33
33
|
setError: (
|
|
34
34
|
error:
|
|
@@ -91,4 +91,7 @@ export const useAlert = function <BER extends object = BackendErrorResource>({
|
|
|
91
91
|
return { backendErrorInfo, setError }
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
export
|
|
94
|
+
export const useAlert = useApiError
|
|
95
|
+
|
|
96
|
+
export type UseApiErrorType = ReturnType<typeof useApiError>
|
|
97
|
+
export type UseAlertType = UseApiErrorType
|
package/app/composables/index.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { useEntity, useFlash } from '@vesperjs/shared'
|
|
|
3
3
|
export type { QueryAPIOptions } from './backend'
|
|
4
4
|
|
|
5
5
|
export { createFetch, createRequestFetch, useOFetch, useMutationApi, useQueryApi } from './backend'
|
|
6
|
-
export { useExternalErrors, useAlert } from './backend'
|
|
6
|
+
export { useExternalErrors, useApiError, useAlert } from './backend'
|
|
7
7
|
|
|
8
8
|
export { useDate } from './util'
|
|
9
9
|
|
|
10
|
-
export type { UseAlertType } from './backend'
|
|
10
|
+
export type { UseApiErrorType, UseAlertType } from './backend'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesperjs/nuxt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"nuxt",
|
|
6
6
|
"vue.js"
|
|
@@ -22,18 +22,18 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@formkit/tempo": "^1.0.0",
|
|
24
24
|
"@nuxt/eslint": "1.15.2",
|
|
25
|
-
"@nuxtjs/i18n": "^10.
|
|
25
|
+
"@nuxtjs/i18n": "^10.3.0",
|
|
26
26
|
"@types/node": "^24.12.2",
|
|
27
|
-
"@vesperjs/shared": "0.3.
|
|
28
|
-
"eslint": "^10.2.
|
|
27
|
+
"@vesperjs/shared": "0.3.3",
|
|
28
|
+
"eslint": "^10.2.1",
|
|
29
29
|
"eslint-typegen": "2.3.1",
|
|
30
30
|
"nuxt": "^4.3.1",
|
|
31
31
|
"ofetch": "^1.5.1",
|
|
32
|
-
"oxfmt": "^0.
|
|
33
|
-
"typescript": "^6.0.
|
|
32
|
+
"oxfmt": "^0.47.0",
|
|
33
|
+
"typescript": "^6.0.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"vue": "^3.5.
|
|
36
|
+
"vue": "^3.5.33 || ^3.6.0-beta.10"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"dev": "nuxi dev .playground",
|