@vesperjs/vue 0.3.2 → 0.4.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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BackendErrorInfo, BackendErrorResource, ErrorMessages, ErrorsResource, Flash, UseFlashType, useDate, useEntity, useExternalErrors, useFlash } from "@vesperjs/shared";
2
2
  import { Ref, WritableComputedRef } from "@vue/reactivity";
3
- import { FetchError, FetchOptions, FetchResponse } from "ofetch";
3
+ import { FetchContext, FetchError, FetchOptions, FetchResponse } from "ofetch";
4
4
  import * as _$vue_i18n0 from "vue-i18n";
5
5
  import * as _$vue from "vue";
6
6
  import * as _$_nanostores_router0 from "@nanostores/router";
@@ -23,7 +23,12 @@ type SearchParams = Record<string, any>;
23
23
  interface QueryAPIOptions {
24
24
  query?: SearchParams;
25
25
  token?: string | null | undefined;
26
+ baseURL?: string | null | undefined;
26
27
  signal?: AbortSignal;
28
+ retry?: number | false;
29
+ retryDelay?: number | ((context: FetchContext<any, 'json'>) => number);
30
+ retryStatusCodes?: number[];
31
+ timeout?: number;
27
32
  onRequestError?: ({
28
33
  error
29
34
  }: {
@@ -49,6 +54,11 @@ interface MutationAPIOptions {
49
54
  method: 'post' | 'put' | 'delete';
50
55
  body?: Record<string, any> | FormData;
51
56
  token?: string | null;
57
+ baseURL?: string | null;
58
+ retry?: number | false;
59
+ retryDelay?: number | ((context: FetchContext<any, 'json'>) => number);
60
+ retryStatusCodes?: number[];
61
+ timeout?: number;
52
62
  onRequestError?: ({
53
63
  error
54
64
  }: {
@@ -64,6 +74,11 @@ declare const useMutationApi: <T = unknown, E = any>(url: string, {
64
74
  method,
65
75
  body,
66
76
  token,
77
+ baseURL,
78
+ retry,
79
+ retryDelay,
80
+ retryStatusCodes,
81
+ timeout,
67
82
  onRequestError,
68
83
  onResponseError
69
84
  }: MutationAPIOptions) => Promise<{
package/dist/index.mjs CHANGED
@@ -88,12 +88,12 @@ const useHttpHeaders = function() {
88
88
  //#region src/composables/backend/api/use-query-api.ts
89
89
  const useQueryApi = async function(url, options) {
90
90
  const { commonHeaders } = useHttpHeaders();
91
- const { baseURL } = useApiConstants();
91
+ const { baseURL: baseUrl } = useApiConstants();
92
92
  const tokenRef = ref();
93
93
  const headers = commonHeaders.value;
94
94
  if (options?.token) headers.Authorization = `Bearer ${options.token}`;
95
95
  const getOptions = {
96
- baseURL: baseURL.value,
96
+ baseURL: options?.baseURL ?? baseUrl.value,
97
97
  method: "get",
98
98
  query: options?.query ?? {},
99
99
  headers,
@@ -101,6 +101,10 @@ const useQueryApi = async function(url, options) {
101
101
  tokenRef.value = response.headers.get("Authorization")?.split(" ")[1] ?? options?.token;
102
102
  }
103
103
  };
104
+ if (options?.retry) getOptions.retry = options.retry;
105
+ if (options?.retryDelay) getOptions.retryDelay = options.retryDelay;
106
+ if (options?.retryStatusCodes) getOptions.retryStatusCodes = options.retryStatusCodes;
107
+ if (options?.timeout) getOptions.timeout = options.timeout;
104
108
  if (options?.signal) getOptions.signal = options.signal;
105
109
  if (options?.onRequestError) getOptions.onRequestError = options.onRequestError;
106
110
  if (options?.onResponseError) getOptions.onResponseError = options.onResponseError;
@@ -114,20 +118,21 @@ const useQueryApi = async function(url, options) {
114
118
  };
115
119
  //#endregion
116
120
  //#region src/composables/backend/api/use-mutation-api.ts
117
- const useMutationApi = async function(url, { method, body = {}, token = null, onRequestError, onResponseError }) {
121
+ const useMutationApi = async function(url, { method, body = {}, token = null, baseURL = null, retry, retryDelay, retryStatusCodes, timeout, onRequestError, onResponseError }) {
118
122
  const { commonHeaders } = useHttpHeaders();
119
- const { baseURL } = useApiConstants();
123
+ const { baseURL: baseUrl } = useApiConstants();
120
124
  const headers = commonHeaders.value;
121
125
  const tokenRef = ref();
122
- if (token) {
123
- headers.Authorization = `Bearer ${token}`;
124
- tokenRef.value = token;
125
- }
126
+ if (token) headers.Authorization = `Bearer ${token}`;
126
127
  const options = {
127
- baseURL: baseURL.value,
128
+ baseURL: baseURL ?? baseUrl.value,
128
129
  headers,
129
130
  method
130
131
  };
132
+ if (retry) options.retry = retry;
133
+ if (retryDelay) options.retryDelay = retryDelay;
134
+ if (retryStatusCodes) options.retryStatusCodes = retryStatusCodes;
135
+ if (timeout) options.timeout = timeout;
131
136
  if (onRequestError) options.onRequestError = onRequestError;
132
137
  if (onResponseError) options.onResponseError = onResponseError;
133
138
  if (method == "post" || method == "put") options.body = body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesperjs/vue",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "keywords": [
5
5
  "vue.js"
6
6
  ],
@@ -22,7 +22,7 @@
22
22
  "@formkit/tempo": "^1.0.0",
23
23
  "@nanostores/persistent": "^1.3.4",
24
24
  "@nanostores/router": "^1.0.0",
25
- "@vesperjs/shared": "0.3.2",
25
+ "@vesperjs/shared": "0.4.0",
26
26
  "nanostores": "^1.3.0",
27
27
  "ofetch": "^1.5.1",
28
28
  "undici": "^8.1.0",
@@ -30,15 +30,12 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@eslint/js": "^10.0.1",
33
- "@typescript-eslint/eslint-plugin": "^8.59.0",
34
- "@typescript-eslint/parser": "^8.59.0",
35
- "@typescript-eslint/project-service": "^8.59.0",
36
- "@typescript-eslint/typescript-estree": "^8.59.0",
37
- "@typescript-eslint/utils": "^8.59.0",
33
+ "@typescript-eslint/eslint-plugin": "^8.59.1",
34
+ "@typescript-eslint/parser": "^8.59.1",
38
35
  "@vue/eslint-config-typescript": "^14.7.0",
39
36
  "eslint": "^10.2.1",
40
37
  "eslint-plugin-vue": "^10.9.0",
41
- "oxfmt": "^0.46.0",
38
+ "oxfmt": "^0.47.0",
42
39
  "tsdown": "^0.21.10",
43
40
  "typescript": "^6.0.3"
44
41
  },