@websolutespa/bom-mixer-hooks 1.0.0 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,37 +1,43 @@
1
- # @websolutespa/bom-mixer-hooks
2
-
3
- ## 0.3.0
4
-
5
- ### Minor Changes
6
-
7
- - Added: useScrolled.
8
-
9
- ## 0.2.2
10
-
11
- ### Patch Changes
12
-
13
- - Modified: useBreakpoint theme mediaQuery.
14
-
15
- ## 0.2.1
16
-
17
- ### Patch Changes
18
-
19
- - Added: source files.
20
-
21
- ## 0.2.0
22
-
23
- ### Minor Changes
24
-
25
- - Added: splat routes.
26
-
27
- ## 0.1.0
28
-
29
- ### Minor Changes
30
-
31
- - Added: @websolutespa/bom-core.
32
-
33
- ## 0.0.2
34
-
35
- ### Patch Changes
36
-
37
- - Added: first release.
1
+ # @websolutespa/bom-mixer-hooks
2
+
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Modified: useHttp, useApi.
8
+
9
+ ## 1.0.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Added: useScrolled.
14
+
15
+ ## 0.2.2
16
+
17
+ ### Patch Changes
18
+
19
+ - Modified: useBreakpoint theme mediaQuery.
20
+
21
+ ## 0.2.1
22
+
23
+ ### Patch Changes
24
+
25
+ - Added: source files.
26
+
27
+ ## 0.2.0
28
+
29
+ ### Minor Changes
30
+
31
+ - Added: splat routes.
32
+
33
+ ## 0.1.0
34
+
35
+ ### Minor Changes
36
+
37
+ - Added: @websolutespa/bom-core.
38
+
39
+ ## 0.0.2
40
+
41
+ ### Patch Changes
42
+
43
+ - Added: first release.
package/dist/index.d.ts CHANGED
@@ -1,24 +1,26 @@
1
1
  import * as React$1 from 'react';
2
2
  import React__default, { RefObject, Dispatch, SetStateAction, MutableRefObject, ComponentProps, useEffect } from 'react';
3
- import { FetchRequestOptions, ISchema, IEquatable, ILayout, IPage } from '@websolutespa/bom-core';
3
+ import { ApiRequestOptions } from '@websolutespa/bom-mixer-store';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
  import * as zustand_middleware from 'zustand/middleware';
5
6
  import { StateStorage } from 'zustand/middleware';
6
7
  import * as zustand from 'zustand';
8
+ import { ISchema, IEquatable, ILayout, IPage } from '@websolutespa/bom-core';
7
9
  import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, IFeatureType, IUser } from '@websolutespa/bom-mixer-models';
8
10
  import { NextRouter } from 'next/router';
9
11
 
10
- declare function useApiFetch<T = any>(pathname: string, options?: FetchRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
11
- declare function useApiGet<T = any>(pathname: string, options?: FetchRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
12
- declare function useApiPost<T = any>(pathname: string, payload: unknown, options?: FetchRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
13
- declare function useApiPut<T = any>(pathname: string, payload: unknown, options?: FetchRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
14
- declare function useApiPatch<T = any>(pathname: string, payload: unknown, options?: FetchRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
15
- declare function useApiDelete<T = any>(pathname: string, options?: FetchRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
12
+ declare function useApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
13
+ declare function useApiGet<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
14
+ declare function useApiPost<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
15
+ declare function useApiPut<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
16
+ declare function useApiPatch<T = unknown>(pathname: string, payload: unknown, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
17
+ declare function useApiDelete<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
16
18
  type Api = {
17
- get: <T = any>(pathname: string, options?: FetchRequestOptions) => Promise<T>;
18
- post: <T = any>(pathname: string, payload?: unknown, options?: FetchRequestOptions) => Promise<T>;
19
- put: <T = any>(pathname: string, payload?: unknown, options?: FetchRequestOptions) => Promise<T>;
20
- patch: <T = any>(pathname: string, payload?: unknown, options?: FetchRequestOptions) => Promise<T>;
21
- delete: <T = any>(pathname: string, options?: FetchRequestOptions) => Promise<T>;
19
+ get: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;
20
+ post: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
21
+ put: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
22
+ patch: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
23
+ delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;
22
24
  };
23
25
  declare function useApi(): Api;
24
26
 
@@ -73,8 +75,8 @@ type CartProviderProps = React.PropsWithChildren<{
73
75
  items?: ICartItem[];
74
76
  storage?: StateStorage;
75
77
  }>;
76
- declare function CartProvider({ children, ...props }: CartProviderProps): JSX.Element;
77
- declare function useCart<T>(selector: (state: CartState) => T, equalityFn?: (left: T, right: T) => boolean): T;
78
+ declare function CartProvider({ children, ...props }: CartProviderProps): react_jsx_runtime.JSX.Element;
79
+ declare function useCart<T>(selector: (state: CartState) => T): T;
78
80
 
79
81
  type CheckoutProps = {
80
82
  hydrated: boolean;
@@ -103,8 +105,8 @@ type CheckoutProviderProps = React.PropsWithChildren<{
103
105
  checkout?: ICheckoutPartial;
104
106
  storage?: StateStorage;
105
107
  }>;
106
- declare function CheckoutProvider({ children, ...props }: CheckoutProviderProps): JSX.Element;
107
- declare function useCheckout<T>(selector: (state: CheckoutState) => T, equalityFn?: (left: T, right: T) => boolean): T;
108
+ declare function CheckoutProvider({ children, ...props }: CheckoutProviderProps): react_jsx_runtime.JSX.Element;
109
+ declare function useCheckout<T>(selector: (state: CheckoutState) => T): T;
108
110
 
109
111
  declare function useClickAnyWhere(handler: (event: MouseEvent) => void): void;
110
112
 
@@ -375,7 +377,7 @@ type ILabelContext = (key: string, params?: {
375
377
  declare const useLabel: () => ILabelContext;
376
378
  declare function LabelProvider({ children }: {
377
379
  children?: React__default.ReactNode;
378
- }): JSX.Element;
380
+ }): react_jsx_runtime.JSX.Element;
379
381
  declare function parseParams(label: string, params: {
380
382
  [key: string]: any;
381
383
  }): string;
@@ -385,7 +387,7 @@ declare const useLayout: () => ILayout;
385
387
  declare function LayoutProvider({ children, layout }: {
386
388
  children?: React__default.ReactNode;
387
389
  layout: ILayout;
388
- }): JSX.Element;
390
+ }): react_jsx_runtime.JSX.Element;
389
391
 
390
392
  declare function useModal(): [modal: UIValue, open: (value?: string) => void, close: () => void];
391
393
 
@@ -398,7 +400,7 @@ declare const usePage: () => NonNullable<IPage>;
398
400
  declare function PageProvider({ children, page }: {
399
401
  children?: React__default.ReactNode;
400
402
  page: IPage;
401
- }): JSX.Element;
403
+ }): react_jsx_runtime.JSX.Element;
402
404
 
403
405
  type IPaginationInfo<T> = {
404
406
  items: T[];
package/dist/index.js CHANGED
@@ -219,7 +219,7 @@ function LayoutProvider({ children, layout }) {
219
219
  // src/useApi/useApi.ts
220
220
  function useApiFetch(pathname, options = {}) {
221
221
  const layout = useLayout();
222
- return useHttpFetch(pathname, options, import_bom_mixer_store.apiFetch, layout);
222
+ return useHttpFetch(pathname, options, import_bom_mixer_store.localApiFetch, layout);
223
223
  }
224
224
  function useApiGet(pathname, options = {}) {
225
225
  return useApiFetch(pathname, __spreadProps(__spreadValues({}, options), { method: "GET" }));
@@ -240,19 +240,19 @@ function useApi() {
240
240
  const layout = useLayout();
241
241
  return {
242
242
  get: (_0, ..._1) => __async(this, [_0, ..._1], function* (pathname, options = {}) {
243
- return (0, import_bom_mixer_store.apiGet)(pathname, options, layout);
243
+ return (0, import_bom_mixer_store.localApiGet)(pathname, options, layout);
244
244
  }),
245
245
  post: (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (pathname, payload, options = {}) {
246
- return (0, import_bom_mixer_store.apiPost)(pathname, payload, options, layout);
246
+ return (0, import_bom_mixer_store.localApiPost)(pathname, payload, options, layout);
247
247
  }),
248
248
  put: (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (pathname, payload, options = {}) {
249
- return (0, import_bom_mixer_store.apiPut)(pathname, payload, options, layout);
249
+ return (0, import_bom_mixer_store.localApiPut)(pathname, payload, options, layout);
250
250
  }),
251
251
  patch: (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (pathname, payload, options = {}) {
252
- return (0, import_bom_mixer_store.apiPatch)(pathname, payload, options, layout);
252
+ return (0, import_bom_mixer_store.localApiPatch)(pathname, payload, options, layout);
253
253
  }),
254
254
  delete: (_0, ..._1) => __async(this, [_0, ..._1], function* (pathname, options = {}) {
255
- return (0, import_bom_mixer_store.apiDelete)(pathname, options, layout);
255
+ return (0, import_bom_mixer_store.localApiDelete)(pathname, options, layout);
256
256
  })
257
257
  };
258
258
  }
@@ -489,11 +489,11 @@ function CartProvider(_a) {
489
489
  }
490
490
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CartContext.Provider, { value: storeRef.current, children });
491
491
  }
492
- function useCart(selector, equalityFn) {
492
+ function useCart(selector) {
493
493
  const store = (0, import_react8.useContext)(CartContext);
494
494
  if (!store)
495
495
  throw new Error("Missing CartContext.Provider in the tree");
496
- return (0, import_zustand.useStore)(store, selector, equalityFn);
496
+ return (0, import_zustand.useStore)(store, selector);
497
497
  }
498
498
 
499
499
  // src/useCheckout/useCheckout.tsx
@@ -549,11 +549,11 @@ function CheckoutProvider(_a) {
549
549
  }
550
550
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CheckoutContext.Provider, { value: storeRef.current, children });
551
551
  }
552
- function useCheckout(selector, equalityFn) {
552
+ function useCheckout(selector) {
553
553
  const store = (0, import_react9.useContext)(CheckoutContext);
554
554
  if (!store)
555
555
  throw new Error("Missing CheckoutContext.Provider in the tree");
556
- return (0, import_zustand2.useStore)(store, selector, equalityFn);
556
+ return (0, import_zustand2.useStore)(store, selector);
557
557
  }
558
558
 
559
559
  // src/useClickAnyWhere/useClickAnyWhere.ts
package/dist/index.mjs CHANGED
@@ -51,7 +51,7 @@ var __async = (__this, __arguments, generator) => {
51
51
  };
52
52
 
53
53
  // src/useApi/useApi.ts
54
- import { apiDelete, apiFetch, apiGet, apiPatch, apiPost, apiPut } from "@websolutespa/bom-mixer-store";
54
+ import { localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut } from "@websolutespa/bom-mixer-store";
55
55
 
56
56
  // src/useHttp/useHttp.ts
57
57
  import { httpFetch } from "@websolutespa/bom-core";
@@ -101,7 +101,7 @@ function LayoutProvider({ children, layout }) {
101
101
  // src/useApi/useApi.ts
102
102
  function useApiFetch(pathname, options = {}) {
103
103
  const layout = useLayout();
104
- return useHttpFetch(pathname, options, apiFetch, layout);
104
+ return useHttpFetch(pathname, options, localApiFetch, layout);
105
105
  }
106
106
  function useApiGet(pathname, options = {}) {
107
107
  return useApiFetch(pathname, __spreadProps(__spreadValues({}, options), { method: "GET" }));
@@ -122,19 +122,19 @@ function useApi() {
122
122
  const layout = useLayout();
123
123
  return {
124
124
  get: (_0, ..._1) => __async(this, [_0, ..._1], function* (pathname, options = {}) {
125
- return apiGet(pathname, options, layout);
125
+ return localApiGet(pathname, options, layout);
126
126
  }),
127
127
  post: (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (pathname, payload, options = {}) {
128
- return apiPost(pathname, payload, options, layout);
128
+ return localApiPost(pathname, payload, options, layout);
129
129
  }),
130
130
  put: (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (pathname, payload, options = {}) {
131
- return apiPut(pathname, payload, options, layout);
131
+ return localApiPut(pathname, payload, options, layout);
132
132
  }),
133
133
  patch: (_0, _1, ..._2) => __async(this, [_0, _1, ..._2], function* (pathname, payload, options = {}) {
134
- return apiPatch(pathname, payload, options, layout);
134
+ return localApiPatch(pathname, payload, options, layout);
135
135
  }),
136
136
  delete: (_0, ..._1) => __async(this, [_0, ..._1], function* (pathname, options = {}) {
137
- return apiDelete(pathname, options, layout);
137
+ return localApiDelete(pathname, options, layout);
138
138
  })
139
139
  };
140
140
  }
@@ -371,11 +371,11 @@ function CartProvider(_a) {
371
371
  }
372
372
  return /* @__PURE__ */ jsx2(CartContext.Provider, { value: storeRef.current, children });
373
373
  }
374
- function useCart(selector, equalityFn) {
374
+ function useCart(selector) {
375
375
  const store = useContext3(CartContext);
376
376
  if (!store)
377
377
  throw new Error("Missing CartContext.Provider in the tree");
378
- return useStore(store, selector, equalityFn);
378
+ return useStore(store, selector);
379
379
  }
380
380
 
381
381
  // src/useCheckout/useCheckout.tsx
@@ -431,11 +431,11 @@ function CheckoutProvider(_a) {
431
431
  }
432
432
  return /* @__PURE__ */ jsx3(CheckoutContext.Provider, { value: storeRef.current, children });
433
433
  }
434
- function useCheckout(selector, equalityFn) {
434
+ function useCheckout(selector) {
435
435
  const store = useContext4(CheckoutContext);
436
436
  if (!store)
437
437
  throw new Error("Missing CheckoutContext.Provider in the tree");
438
- return useStore2(store, selector, equalityFn);
438
+ return useStore2(store, selector);
439
439
  }
440
440
 
441
441
  // src/useClickAnyWhere/useClickAnyWhere.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-hooks",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Mixer Hooks module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -34,7 +34,7 @@
34
34
  "react": ">= 18.2.0",
35
35
  "styled-components": ">= 5.3.5",
36
36
  "swiper": ">= 8.3.2",
37
- "zustand": ">= 4.1.1"
37
+ "zustand": ">= 4.4.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.0.18",
@@ -2,7 +2,7 @@ import '@testing-library/jest-dom';
2
2
  import { render, renderHook, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
3
3
  import { ILayout } from '@websolutespa/bom-core';
4
4
  import { LayoutDefaults } from '@websolutespa/bom-mixer-mock';
5
- import { getApiUrl } from '@websolutespa/bom-mixer-store';
5
+ import { getLocalApiUrl } from '@websolutespa/bom-mixer-store';
6
6
  import { LayoutProvider } from '../useLayout/useLayout';
7
7
  import { useApi, useApiDelete, useApiFetch, useApiGet, useApiPatch, useApiPost, useApiPut } from './useApi';
8
8
 
@@ -22,7 +22,7 @@ function mockFetch(
22
22
  overrideResponse: Partial<typeof defaultResponse> = {}
23
23
  ) {
24
24
  const endpoint = '/endpoint';
25
- const url = `${getApiUrl(endpoint)}?locale=en&market=ww`;
25
+ const url = `${getLocalApiUrl(endpoint)}?locale=en&market=ww`;
26
26
  const payload = { data: 'data' };
27
27
  const response = {
28
28
  ...defaultResponse,
@@ -38,6 +38,7 @@ function mockFetch(
38
38
  method: string;
39
39
  } = {
40
40
  headers: {
41
+ 'Authorization': 'Bearer STORE_BEARER',
41
42
  'Content-Type': 'application/json',
42
43
  },
43
44
  method,
@@ -56,18 +57,18 @@ describe('useApi', () => {
56
57
  jest.resetModules();
57
58
  jest.resetAllMocks();
58
59
  jest.spyOn(console, 'error').mockImplementation(() => { });
60
+ jest.spyOn(console, 'log').mockImplementation(() => { });
59
61
  process.env = {
60
62
  NODE_ENV: 'test',
61
63
  NEXT_PUBLIC_URL: 'http://localhost:3000',
62
64
  NEXT_PUBLIC_MOCK_FALLBACK_URL: 'http://localhost:3000',
63
65
  NEXT_PUBLIC_API: '/api',
64
- NEXT_PUBLIC_GOOGLE_MAP_API_KEY: 'AIzaSyDvGw6iAoKdRv8mmaC9GeT-LWLPQtA8p60',
65
66
  STORE_URL: 'http://localhost:4000',
66
67
  STORE_API: '/bowl/api',
67
- STORE_BEARER: '7584f15d12972fb1e7695e998dd5e4c754f46c74d06a08e8d76f556adcd045e48cd52bed6faac098784471ac273ee40243194b9cff7eba3c4a768f8f41d2d51959a7f767b943c7f0170f6e5f632db523803c357083bf7a7bf03ee8e0df2d8ce5cd52e0211283b34d7781313da775018a9e950433d2b6faf711c20e5a63b25243',
68
68
  STORE_STRATEGY: 'mock',
69
- SECRET_COOKIE_PASSWORD: '2gyZ3GDw3LHZQKDhPmPDL3sjREVRXPr8',
70
- HOOKS_SECRET: '7584f15d12972fb1e7695e998dd5e4',
69
+ STORE_BEARER: 'STORE_BEARER',
70
+ SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD',
71
+ HOOKS_SECRET: 'HOOKS_SECRET',
71
72
  };
72
73
  });
73
74
 
@@ -1,58 +1,59 @@
1
- import { FetchRequestOptions } from '@websolutespa/bom-core';
2
- import { apiDelete, apiFetch, apiGet, apiPatch, apiPost, apiPut } from '@websolutespa/bom-mixer-store';
1
+ import { ApiRequestOptions, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut } from '@websolutespa/bom-mixer-store';
3
2
  import { useHttpFetch } from '../useHttp/useHttp';
4
3
  import { useLayout } from '../useLayout/useLayout';
5
4
 
6
- export function useApiFetch<T = any>(pathname: string, options: FetchRequestOptions = {}) {
5
+ export function useApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {
7
6
  const layout = useLayout();
8
- return useHttpFetch<T>(pathname, options, apiFetch, layout);
7
+ // const layout = { locale: '', market: '' };
8
+ return useHttpFetch<T>(pathname, options, localApiFetch, layout);
9
9
  }
10
10
 
11
- export function useApiGet<T = any>(pathname: string, options: FetchRequestOptions = {}) {
11
+ export function useApiGet<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {
12
12
  return useApiFetch<T>(pathname, { ...options, method: 'GET' });
13
13
  }
14
14
 
15
- export function useApiPost<T = any>(pathname: string, payload: unknown, options: FetchRequestOptions = {}) {
15
+ export function useApiPost<T = unknown>(pathname: string, payload: unknown, options: ApiRequestOptions = {}) {
16
16
  return useApiFetch<T>(pathname, { ...options, method: 'POST', body: payload ? JSON.stringify(payload) : undefined });
17
17
  }
18
18
 
19
- export function useApiPut<T = any>(pathname: string, payload: unknown, options: FetchRequestOptions = {}) {
19
+ export function useApiPut<T = unknown>(pathname: string, payload: unknown, options: ApiRequestOptions = {}) {
20
20
  return useApiFetch<T>(pathname, { ...options, method: 'PUT', body: payload ? JSON.stringify(payload) : undefined });
21
21
  }
22
22
 
23
- export function useApiPatch<T = any>(pathname: string, payload: unknown, options: FetchRequestOptions = {}) {
23
+ export function useApiPatch<T = unknown>(pathname: string, payload: unknown, options: ApiRequestOptions = {}) {
24
24
  return useApiFetch<T>(pathname, { ...options, method: 'PATCH', body: payload ? JSON.stringify(payload) : undefined });
25
25
  }
26
26
 
27
- export function useApiDelete<T = any>(pathname: string, options: FetchRequestOptions = {}) {
27
+ export function useApiDelete<T = unknown>(pathname: string, options: ApiRequestOptions = {}) {
28
28
  return useApiFetch<T>(pathname, { ...options, method: 'DELETE' });
29
29
  }
30
30
 
31
31
  type Api = {
32
- get: <T = any>(pathname: string, options?: FetchRequestOptions) => Promise<T>;
33
- post: <T = any>(pathname: string, payload?: unknown, options?: FetchRequestOptions) => Promise<T>;
34
- put: <T = any>(pathname: string, payload?: unknown, options?: FetchRequestOptions) => Promise<T>;
35
- patch: <T = any>(pathname: string, payload?: unknown, options?: FetchRequestOptions) => Promise<T>;
36
- delete: <T = any>(pathname: string, options?: FetchRequestOptions) => Promise<T>;
32
+ get: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;
33
+ post: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
34
+ put: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
35
+ patch: <T = unknown>(pathname: string, payload?: unknown, options?: ApiRequestOptions) => Promise<T>;
36
+ delete: <T = unknown>(pathname: string, options?: ApiRequestOptions) => Promise<T>;
37
37
  };
38
38
 
39
39
  export function useApi(): Api {
40
40
  const layout = useLayout();
41
+ // const layout = { locale: '', market: '' };
41
42
  return {
42
- get: async <T = any>(pathname: string, options: FetchRequestOptions = {}) => {
43
- return apiGet<T>(pathname, options, layout);
43
+ get: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {
44
+ return localApiGet<T>(pathname, options, layout);
44
45
  },
45
- post: async <T = any>(pathname: string, payload?: unknown, options: FetchRequestOptions = {}) => {
46
- return apiPost<T>(pathname, payload, options, layout);
46
+ post: async <T = unknown>(pathname: string, payload?: unknown, options: ApiRequestOptions = {}) => {
47
+ return localApiPost<T>(pathname, payload, options, layout);
47
48
  },
48
- put: async <T = any>(pathname: string, payload?: unknown, options: FetchRequestOptions = {}) => {
49
- return apiPut<T>(pathname, payload, options, layout);
49
+ put: async <T = unknown>(pathname: string, payload?: unknown, options: ApiRequestOptions = {}) => {
50
+ return localApiPut<T>(pathname, payload, options, layout);
50
51
  },
51
- patch: async <T = any>(pathname: string, payload?: unknown, options: FetchRequestOptions = {}) => {
52
- return apiPatch<T>(pathname, payload, options, layout);
52
+ patch: async <T = unknown>(pathname: string, payload?: unknown, options: ApiRequestOptions = {}) => {
53
+ return localApiPatch<T>(pathname, payload, options, layout);
53
54
  },
54
- delete: async <T = any>(pathname: string, options: FetchRequestOptions = {}) => {
55
- return apiDelete<T>(pathname, options, layout);
55
+ delete: async <T = unknown>(pathname: string, options: ApiRequestOptions = {}) => {
56
+ return localApiDelete<T>(pathname, options, layout);
56
57
  },
57
58
  };
58
59
  }
@@ -119,13 +119,10 @@ function CartProvider({ children, ...props }: CartProviderProps) {
119
119
  );
120
120
  }
121
121
 
122
- function useCart<T>(
123
- selector: (state: CartState) => T,
124
- equalityFn?: (left: T, right: T) => boolean
125
- ): T {
122
+ function useCart<T>(selector: (state: CartState) => T): T {
126
123
  const store = useContext(CartContext);
127
124
  if (!store) throw new Error('Missing CartContext.Provider in the tree');
128
- return useStore(store, selector, equalityFn);
125
+ return useStore(store, selector);
129
126
  }
130
127
 
131
128
  export { CartProvider, useCart };
@@ -1,7 +1,7 @@
1
1
  import { IAddressOptions, ICheckoutPartial } from '@websolutespa/bom-mixer-models';
2
2
  import { createContext, useContext, useRef } from 'react';
3
3
  import { createStore, useStore } from 'zustand';
4
- import { createJSONStorage, persist, StateStorage } from 'zustand/middleware';
4
+ import { StateStorage, createJSONStorage, persist } from 'zustand/middleware';
5
5
 
6
6
  type CheckoutInitialProps = {
7
7
  data: IAddressOptions;
@@ -82,13 +82,10 @@ function CheckoutProvider({ children, ...props }: CheckoutProviderProps) {
82
82
  );
83
83
  }
84
84
 
85
- function useCheckout<T>(
86
- selector: (state: CheckoutState) => T,
87
- equalityFn?: (left: T, right: T) => boolean
88
- ): T {
85
+ function useCheckout<T>(selector: (state: CheckoutState) => T): T {
89
86
  const store = useContext(CheckoutContext);
90
87
  if (!store) throw new Error('Missing CheckoutContext.Provider in the tree');
91
- return useStore(store, selector, equalityFn);
88
+ return useStore(store, selector);
92
89
  }
93
90
 
94
91
  export { CheckoutProvider, useCheckout };
@@ -1,6 +1,6 @@
1
1
  import '@testing-library/jest-dom';
2
2
  import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
3
- import { getApiUrl } from '@websolutespa/bom-mixer-store';
3
+ import { getLocalApiUrl } from '@websolutespa/bom-mixer-store';
4
4
  import { useHttpDelete, useHttpFetch, useHttpGet, useHttpPatch, useHttpPost, useHttpPut } from './useHttp';
5
5
 
6
6
  const defaultResponse = {
@@ -12,7 +12,7 @@ const defaultResponse = {
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
  function mockFetch(method: string = 'GET', result: any = { message: 'ok' }, overrideResponse: Partial<typeof defaultResponse> = {}) {
14
14
  const endpoint = '/endpoint';
15
- const url = `${getApiUrl(endpoint)}?locale=en&market=ww`;
15
+ const url = `${getLocalApiUrl(endpoint)}?locale=en&market=ww`;
16
16
  const payload = { data: 'data' };
17
17
  const response = {
18
18
  ...defaultResponse,
@@ -45,22 +45,21 @@ describe('useHttp', () => {
45
45
  const FETCH = global.fetch;
46
46
 
47
47
  beforeEach(() => {
48
- // !!! act error
49
- jest.spyOn(console, 'error').mockImplementation(() => { });
50
48
  jest.resetModules();
51
49
  jest.resetAllMocks();
50
+ jest.spyOn(console, 'error').mockImplementation(() => { });
51
+ jest.spyOn(console, 'log').mockImplementation(() => { });
52
52
  process.env = {
53
53
  NODE_ENV: 'test',
54
54
  NEXT_PUBLIC_URL: 'http://localhost:3000',
55
55
  NEXT_PUBLIC_MOCK_FALLBACK_URL: 'http://localhost:3000',
56
56
  NEXT_PUBLIC_API: '/api',
57
- NEXT_PUBLIC_GOOGLE_MAP_API_KEY: 'AIzaSyDvGw6iAoKdRv8mmaC9GeT-LWLPQtA8p60',
58
57
  STORE_URL: 'http://localhost:4000',
59
58
  STORE_API: '/bowl/api',
60
- STORE_BEARER: '7584f15d12972fb1e7695e998dd5e4c754f46c74d06a08e8d76f556adcd045e48cd52bed6faac098784471ac273ee40243194b9cff7eba3c4a768f8f41d2d51959a7f767b943c7f0170f6e5f632db523803c357083bf7a7bf03ee8e0df2d8ce5cd52e0211283b34d7781313da775018a9e950433d2b6faf711c20e5a63b25243',
61
59
  STORE_STRATEGY: 'mock',
62
- SECRET_COOKIE_PASSWORD: '2gyZ3GDw3LHZQKDhPmPDL3sjREVRXPr8',
63
- HOOKS_SECRET: '7584f15d12972fb1e7695e998dd5e4',
60
+ STORE_BEARER: 'STORE_BEARER',
61
+ SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD',
62
+ HOOKS_SECRET: 'HOOKS_SECRET',
64
63
  };
65
64
  });
66
65
 
@@ -1,15 +1,15 @@
1
- import { FetchRequestOptions, FetchService, httpFetch } from '@websolutespa/bom-core';
1
+ import { FetchError, FetchRequestOptions, FetchService, httpFetch } from '@websolutespa/bom-core';
2
2
  import { Dispatch, useEffect, useState } from 'react';
3
3
 
4
- export function useHttpFetch<T = any>(
4
+ export function useHttpFetch<T = unknown>(
5
5
  pathname: string,
6
6
  options: FetchRequestOptions = { method: 'GET' },
7
7
  service: FetchService<T> = httpFetch,
8
- serviceOptions?: any
9
- ): [T | undefined, boolean, any, Dispatch<any>] {
8
+ serviceOptions?: unknown
9
+ ): [T | undefined, boolean, FetchError, Dispatch<FetchError>] {
10
10
  const [response, setResponse] = useState<T>();
11
11
  const [loading, setLoading] = useState<boolean>(false);
12
- const [error, setError] = useState<any>(null);
12
+ const [error, setError] = useState<FetchError>(null);
13
13
  useEffect(() => {
14
14
  // const source = axios.CancelToken.source();
15
15
  const fetchData = async () => {
@@ -19,7 +19,7 @@ export function useHttpFetch<T = any>(
19
19
  const response = await service(pathname, options, serviceOptions);
20
20
  // console.log('useHttp.response', response);
21
21
  setResponse(response);
22
- } catch (error) {
22
+ } catch (error: FetchError) {
23
23
  // console.error(error)
24
24
  setError(error);
25
25
  }
@@ -31,22 +31,22 @@ export function useHttpFetch<T = any>(
31
31
  return [response, loading, error, setError];
32
32
  }
33
33
 
34
- export function useHttpGet<T = any>(pathname: string, options: FetchRequestOptions = {}) {
34
+ export function useHttpGet<T = unknown>(pathname: string, options: FetchRequestOptions = {}) {
35
35
  return useHttpFetch<T>(pathname, { ...options, method: 'GET' });
36
36
  }
37
37
 
38
- export function useHttpPost<T = any>(pathname: string, payload: any, options: FetchRequestOptions = {}) {
38
+ export function useHttpPost<T = unknown>(pathname: string, payload: unknown, options: FetchRequestOptions = {}) {
39
39
  return useHttpFetch<T>(pathname, { ...options, method: 'POST', body: payload ? JSON.stringify(payload) : undefined });
40
40
  }
41
41
 
42
- export function useHttpPut<T = any>(pathname: string, payload: any, options: FetchRequestOptions = {}) {
42
+ export function useHttpPut<T = unknown>(pathname: string, payload: unknown, options: FetchRequestOptions = {}) {
43
43
  return useHttpFetch<T>(pathname, { ...options, method: 'PUT', body: payload ? JSON.stringify(payload) : undefined });
44
44
  }
45
45
 
46
- export function useHttpPatch<T = any>(pathname: string, payload: any, options: FetchRequestOptions = {}) {
46
+ export function useHttpPatch<T = unknown>(pathname: string, payload: unknown, options: FetchRequestOptions = {}) {
47
47
  return useHttpFetch<T>(pathname, { ...options, method: 'PATCH', body: payload ? JSON.stringify(payload) : undefined });
48
48
  }
49
49
 
50
- export function useHttpDelete<T = any>(pathname: string, options: FetchRequestOptions = {}) {
50
+ export function useHttpDelete<T = unknown>(pathname: string, options: FetchRequestOptions = {}) {
51
51
  return useHttpFetch<T>(pathname, { ...options, method: 'DELETE' });
52
52
  }
@@ -15,5 +15,5 @@ function LayoutProvider({ children, layout }: { children?: React.ReactNode, layo
15
15
  );
16
16
  }
17
17
 
18
- export { useLayout, LayoutProvider };
18
+ export { LayoutProvider, useLayout };
19
19
 
@@ -15,5 +15,5 @@ function PageProvider({ children, page }: { children?: React.ReactNode, page: IP
15
15
  );
16
16
  }
17
17
 
18
- export { usePage, PageProvider };
18
+ export { PageProvider, usePage };
19
19