@vesperjs/vue 0.2.2 → 0.3.1

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/dist/index.d.mts CHANGED
@@ -22,7 +22,7 @@ declare const useOFetch: <T = unknown, E = any>(url: string, options?: FetchOpti
22
22
  type SearchParams = Record<string, any>;
23
23
  interface QueryAPIOptions {
24
24
  query?: SearchParams;
25
- token?: string | null;
25
+ token?: string | null | undefined;
26
26
  signal?: AbortSignal;
27
27
  onRequestError?: ({
28
28
  error
@@ -38,7 +38,7 @@ interface QueryAPIOptions {
38
38
  cache?: boolean;
39
39
  }
40
40
  declare const useQueryApi: <T = unknown, E = any>(url: string, options?: QueryAPIOptions) => Promise<{
41
- token: string | undefined;
41
+ token: string | null | undefined;
42
42
  data: T | undefined;
43
43
  error: FetchError<E> | undefined;
44
44
  pending: boolean;
@@ -67,7 +67,7 @@ declare const useMutationApi: <T = unknown, E = any>(url: string, {
67
67
  onRequestError,
68
68
  onResponseError
69
69
  }: MutationAPIOptions) => Promise<{
70
- token: string | undefined;
70
+ token: string | null | undefined;
71
71
  data: T | undefined;
72
72
  error: FetchError<E> | undefined;
73
73
  pending: boolean;
package/dist/index.mjs CHANGED
@@ -91,17 +91,14 @@ const useQueryApi = async function(url, options) {
91
91
  const { baseURL } = useApiConstants();
92
92
  const tokenRef = ref();
93
93
  const headers = commonHeaders.value;
94
- if (options?.token) {
95
- headers.Authorization = `Bearer ${options.token}`;
96
- tokenRef.value = options.token;
97
- }
94
+ if (options?.token) headers.Authorization = `Bearer ${options.token}`;
98
95
  const getOptions = {
99
96
  baseURL: baseURL.value,
100
97
  method: "get",
101
98
  query: options?.query ?? {},
102
99
  headers,
103
100
  onResponse({ response }) {
104
- if (!tokenRef.value) tokenRef.value = response.headers.get("Authorization")?.split(" ")[1];
101
+ tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? options?.token;
105
102
  }
106
103
  };
107
104
  if (options?.signal) getOptions.signal = options.signal;
@@ -133,12 +130,10 @@ const useMutationApi = async function(url, { method, body = {}, token = null, on
133
130
  };
134
131
  if (onRequestError) options.onRequestError = onRequestError;
135
132
  if (onResponseError) options.onResponseError = onResponseError;
136
- if (method == "post" || method == "put") {
137
- options.body = body;
138
- options.onResponse = ({ response }) => {
139
- if (method == "post" && !tokenRef.value || method == "put") tokenRef.value = response.headers.get("Authorization")?.split(" ")[1];
140
- };
141
- }
133
+ if (method == "post" || method == "put") options.body = body;
134
+ options.onResponse = ({ response }) => {
135
+ tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? token;
136
+ };
142
137
  const { data, error, pending } = await useOFetch(url, options);
143
138
  return {
144
139
  token: tokenRef.value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesperjs/vue",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "keywords": [
5
5
  "vue.js"
6
6
  ],
@@ -22,31 +22,31 @@
22
22
  "@formkit/tempo": "^1.0.0",
23
23
  "@nanostores/persistent": "^1.3.3",
24
24
  "@nanostores/router": "^1.0.0",
25
- "@vesperjs/shared": "0.2.2",
25
+ "@vesperjs/shared": "0.3.1",
26
26
  "nanostores": "^1.2.0",
27
27
  "ofetch": "^1.5.1",
28
- "undici": "^8.0.2",
28
+ "undici": "^8.1.0",
29
29
  "vue-i18n": "^11.3.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@eslint/js": "^10.0.1",
33
- "@typescript-eslint/eslint-plugin": "^8.58.1",
34
- "@typescript-eslint/parser": "^8.58.1",
35
- "@typescript-eslint/project-service": "^8.58.1",
36
- "@typescript-eslint/typescript-estree": "^8.58.1",
37
- "@typescript-eslint/utils": "^8.58.1",
33
+ "@typescript-eslint/eslint-plugin": "^8.58.2",
34
+ "@typescript-eslint/parser": "^8.58.2",
35
+ "@typescript-eslint/project-service": "^8.58.2",
36
+ "@typescript-eslint/typescript-estree": "^8.58.2",
37
+ "@typescript-eslint/utils": "^8.58.2",
38
38
  "@vue/eslint-config-typescript": "^14.7.0",
39
39
  "eslint": "^10.2.0",
40
40
  "eslint-plugin-vue": "^10.8.0",
41
- "oxfmt": "^0.44.0",
42
- "tsdown": "^0.21.7",
41
+ "oxfmt": "^0.45.0",
42
+ "tsdown": "^0.21.8",
43
43
  "typescript": "^6.0.2"
44
44
  },
45
45
  "peerDependencies": {
46
- "@vue/reactivity": "^3.5.32 || ^3.6.0-beta.9",
47
- "@vue/runtime-core": "^3.5.32 || ^3.6.0-beta.9",
48
- "@vue/runtime-dom": "^3.5.32 || ^3.6.0-beta.9",
49
- "vue": "^3.5.32 || ^3.6.0-beta.9"
46
+ "@vue/reactivity": "^3.5.32 || ^3.6.0-beta.10",
47
+ "@vue/runtime-core": "^3.5.32 || ^3.6.0-beta.10",
48
+ "@vue/runtime-dom": "^3.5.32 || ^3.6.0-beta.10",
49
+ "vue": "^3.5.32 || ^3.6.0-beta.10"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsdown --dts",