@kawaiininja/fetch 1.0.37 → 1.0.39

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.
@@ -8,7 +8,6 @@ export const useFetch = (endpoint, baseOptions = {}) => {
8
8
  const { fetchCSRF } = useCsrf();
9
9
  const abortRef = useRef(new AbortController());
10
10
  const mounted = useRef(true);
11
- const isRequestingRef = useRef(false);
12
11
  // 🛡️ LOCK IDENTITY: Ignore baseOptions identity shifts
13
12
  const optionsRef = useRef(baseOptions);
14
13
  useEffect(() => {
@@ -30,9 +29,6 @@ export const useFetch = (endpoint, baseOptions = {}) => {
30
29
  }, 0);
31
30
  }, []);
32
31
  const request = useCallback(async (params = {}) => {
33
- if (isRequestingRef.current)
34
- return;
35
- isRequestingRef.current = true;
36
32
  if (debug)
37
33
  console.log(`[API] Starting: ${endpoint}`);
38
34
  safeSet(() => ({ loading: true, error: null }));
@@ -62,7 +58,6 @@ export const useFetch = (endpoint, baseOptions = {}) => {
62
58
  }
63
59
  finally {
64
60
  safeSet(() => ({ loading: false }));
65
- isRequestingRef.current = false;
66
61
  }
67
62
  }, [endpoint, fetchCSRF, apiUrl, onError, debug, safeSet]);
68
63
  useEffect(() => {
@@ -33,7 +33,7 @@ interface CreateApiSurfaceParams<T> {
33
33
  /**
34
34
  * Helper to construct the STABLE methods of the API surface.
35
35
  */
36
- export declare const createApiMethods: <T = any>({ request, baseUrl, safeSet, }: Omit<CreateApiSurfaceParams<T>, "state">) => {
36
+ export declare const createApiMethods: <T = any>({ request, baseUrl, safeSet }: Omit<CreateApiSurfaceParams<T>, "state">) => {
37
37
  request: <R = T>(options?: RequestOptions) => Promise<R | undefined>;
38
38
  refetch: () => Promise<T | undefined>;
39
39
  setData: (value: T | null | ((prev: T | null) => T | null)) => void;
@@ -51,5 +51,5 @@ export declare const createApiMethods: <T = any>({ request, baseUrl, safeSet, }:
51
51
  /**
52
52
  * Helper to construct the API surface object.
53
53
  */
54
- export declare const createApiSurface: <T = any>({ state, request, baseUrl, safeSet, }: CreateApiSurfaceParams<T>) => ApiSurface<T>;
54
+ export declare const createApiSurface: <T = any>({ state, request, baseUrl, safeSet }: CreateApiSurfaceParams<T>) => ApiSurface<T>;
55
55
  export {};
@@ -1,13 +1,15 @@
1
+ import { useApiConfig } from "./useApiConfig";
1
2
  /**
2
3
  * Helper to construct the STABLE methods of the API surface.
3
4
  */
4
- export const createApiMethods = ({ request, baseUrl, safeSet, }) => {
5
+ export const createApiMethods = ({ request, baseUrl, safeSet }) => {
5
6
  // little helper for JSON methods
6
7
  const withJsonBody = (data) => ({
7
8
  body: data != null ? JSON.stringify(data) : undefined,
8
9
  headers: { "Content-Type": "application/json" },
9
10
  parseAs: "json",
10
11
  });
12
+ const { apiUrl } = useApiConfig();
11
13
  return {
12
14
  // 🔁 core
13
15
  request,
@@ -15,24 +17,20 @@ export const createApiMethods = ({ request, baseUrl, safeSet, }) => {
15
17
  // 🎯 data helpers
16
18
  setData: (value) => {
17
19
  safeSet((prev) => ({
18
- data: (typeof value === "function"
19
- ? value(prev.data)
20
- : value),
20
+ data: (typeof value === "function" ? value(prev.data) : value),
21
21
  }));
22
22
  },
23
23
  updateData: (partial) => safeSet((prev) => ({
24
24
  data: {
25
25
  ...prev.data,
26
- ...(typeof partial === "function"
27
- ? partial(prev.data)
28
- : partial),
26
+ ...(typeof partial === "function" ? partial(prev.data) : partial),
29
27
  },
30
28
  })),
31
29
  // 🗡 CRUD methods
32
30
  get: (config = {}) => request({ ...config, url: config.url || baseUrl, method: "GET" }),
33
31
  post: (data, config = {}) => request({
34
32
  ...config,
35
- url: config.url || baseUrl,
33
+ url: apiUrl(config.url || "") || baseUrl,
36
34
  method: "POST",
37
35
  ...withJsonBody(data),
38
36
  headers: {
@@ -101,7 +99,7 @@ export const createApiMethods = ({ request, baseUrl, safeSet, }) => {
101
99
  /**
102
100
  * Helper to construct the API surface object.
103
101
  */
104
- export const createApiSurface = ({ state, request, baseUrl, safeSet, }) => {
102
+ export const createApiSurface = ({ state, request, baseUrl, safeSet }) => {
105
103
  const methods = createApiMethods({ request, baseUrl, safeSet });
106
104
  return {
107
105
  // 🔍 state
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kawaiininja/fetch",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "Core fetch utility for Onyx Framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",