@teo-garcia/react-shared 0.1.8 → 1.0.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.
Files changed (84) hide show
  1. package/README.md +76 -168
  2. package/dist/components/error-boundary/error-boundary.d.ts.map +1 -1
  3. package/dist/components/error-boundary/error-boundary.js +1 -1
  4. package/dist/components/index.d.ts +0 -5
  5. package/dist/components/index.d.ts.map +1 -1
  6. package/dist/components/index.js +0 -5
  7. package/dist/hooks/index.d.ts +6 -5
  8. package/dist/hooks/index.d.ts.map +1 -1
  9. package/dist/hooks/index.js +6 -4
  10. package/dist/hooks/use-debounce.d.ts +2 -0
  11. package/dist/hooks/use-debounce.d.ts.map +1 -0
  12. package/dist/hooks/use-debounce.js +9 -0
  13. package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
  14. package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
  15. package/dist/hooks/use-isomorphic-layout-effect.js +4 -0
  16. package/dist/hooks/use-local-storage.d.ts +2 -0
  17. package/dist/hooks/use-local-storage.d.ts.map +1 -0
  18. package/dist/hooks/use-local-storage.js +37 -0
  19. package/dist/hooks/use-media-query.d.ts +2 -0
  20. package/dist/hooks/use-media-query.d.ts.map +1 -0
  21. package/dist/hooks/use-media-query.js +18 -0
  22. package/dist/hooks/use-on-click-outside.d.ts +3 -0
  23. package/dist/hooks/use-on-click-outside.d.ts.map +1 -0
  24. package/dist/hooks/use-on-click-outside.js +17 -0
  25. package/dist/hooks/use-previous.d.ts +2 -0
  26. package/dist/hooks/use-previous.d.ts.map +1 -0
  27. package/dist/hooks/use-previous.js +8 -0
  28. package/dist/index.d.ts +6 -4
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +6 -9
  31. package/dist/test-utils/index.d.ts +14 -0
  32. package/dist/test-utils/index.d.ts.map +1 -0
  33. package/dist/test-utils/index.js +22 -0
  34. package/dist/types.d.ts +0 -34
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/utils/cn.d.ts +3 -0
  37. package/dist/utils/cn.d.ts.map +1 -0
  38. package/dist/utils/cn.js +5 -0
  39. package/dist/utils/index.d.ts +1 -5
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist/utils/index.js +1 -5
  42. package/package.json +62 -45
  43. package/dist/adapters/environment/index.d.ts +0 -6
  44. package/dist/adapters/environment/index.d.ts.map +0 -1
  45. package/dist/adapters/environment/index.js +0 -5
  46. package/dist/adapters/environment/next.d.ts +0 -17
  47. package/dist/adapters/environment/next.d.ts.map +0 -1
  48. package/dist/adapters/environment/next.js +0 -20
  49. package/dist/adapters/environment/vite.d.ts +0 -17
  50. package/dist/adapters/environment/vite.d.ts.map +0 -1
  51. package/dist/adapters/environment/vite.js +0 -20
  52. package/dist/adapters/index.d.ts +0 -9
  53. package/dist/adapters/index.d.ts.map +0 -1
  54. package/dist/adapters/index.js +0 -8
  55. package/dist/adapters/theme/custom.d.ts +0 -32
  56. package/dist/adapters/theme/custom.d.ts.map +0 -1
  57. package/dist/adapters/theme/custom.js +0 -26
  58. package/dist/adapters/theme/index.d.ts +0 -6
  59. package/dist/adapters/theme/index.d.ts.map +0 -1
  60. package/dist/adapters/theme/index.js +0 -5
  61. package/dist/adapters/theme/next-themes.d.ts +0 -18
  62. package/dist/adapters/theme/next-themes.d.ts.map +0 -1
  63. package/dist/adapters/theme/next-themes.js +0 -23
  64. package/dist/components/theme-switch/index.d.ts +0 -3
  65. package/dist/components/theme-switch/index.d.ts.map +0 -1
  66. package/dist/components/theme-switch/index.js +0 -1
  67. package/dist/components/theme-switch/theme-switch.d.ts +0 -36
  68. package/dist/components/theme-switch/theme-switch.d.ts.map +0 -1
  69. package/dist/components/theme-switch/theme-switch.js +0 -74
  70. package/dist/components/viewport-info/index.d.ts +0 -3
  71. package/dist/components/viewport-info/index.d.ts.map +0 -1
  72. package/dist/components/viewport-info/index.js +0 -1
  73. package/dist/components/viewport-info/viewport-info.d.ts +0 -40
  74. package/dist/components/viewport-info/viewport-info.d.ts.map +0 -1
  75. package/dist/components/viewport-info/viewport-info.js +0 -69
  76. package/dist/hooks/use-healthcheck.d.ts +0 -42
  77. package/dist/hooks/use-healthcheck.d.ts.map +0 -1
  78. package/dist/hooks/use-healthcheck.js +0 -53
  79. package/dist/utils/environment.d.ts +0 -71
  80. package/dist/utils/environment.d.ts.map +0 -1
  81. package/dist/utils/environment.js +0 -86
  82. package/dist/utils/msw.d.ts +0 -54
  83. package/dist/utils/msw.d.ts.map +0 -1
  84. package/dist/utils/msw.js +0 -62
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/viewport-info/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -1 +0,0 @@
1
- export { ViewportInfo } from './viewport-info.js';
@@ -1,40 +0,0 @@
1
- import type { EnvironmentAdapter } from '../../types';
2
- export interface ViewportInfoProps {
3
- /** Environment adapter to detect if running in development mode */
4
- environmentAdapter: EnvironmentAdapter;
5
- }
6
- /**
7
- * ViewportInfo component - Displays current viewport dimensions and Tailwind breakpoint
8
- *
9
- * This component is useful during development to see the current viewport size and
10
- * which Tailwind breakpoint is active. It automatically hides in production.
11
- *
12
- * Features:
13
- * - Shows viewport width and height in pixels
14
- * - Displays active Tailwind CSS breakpoint (default, sm, md, lg, xl, 2xl)
15
- * - Auto-updates on window resize
16
- * - Only renders in development mode
17
- * - Fixed position in bottom-right corner
18
- *
19
- * @example Next.js
20
- * ```tsx
21
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
22
- * import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
23
- *
24
- * function App() {
25
- * return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
26
- * }
27
- * ```
28
- *
29
- * @example React Router / Vite
30
- * ```tsx
31
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
32
- * import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
33
- *
34
- * function App() {
35
- * return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
36
- * }
37
- * ```
38
- */
39
- export declare const ViewportInfo: ({ environmentAdapter }: ViewportInfoProps) => import("react/jsx-runtime").JSX.Element | null;
40
- //# sourceMappingURL=viewport-info.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"viewport-info.d.ts","sourceRoot":"","sources":["../../../src/components/viewport-info/viewport-info.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,kBAAkB,EAAE,kBAAkB,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,YAAY,GAAI,wBAAwB,iBAAiB,mDAmDrE,CAAA"}
@@ -1,69 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { RulerIcon } from 'lucide-react';
4
- import { useEffect, useState } from 'react';
5
- /**
6
- * ViewportInfo component - Displays current viewport dimensions and Tailwind breakpoint
7
- *
8
- * This component is useful during development to see the current viewport size and
9
- * which Tailwind breakpoint is active. It automatically hides in production.
10
- *
11
- * Features:
12
- * - Shows viewport width and height in pixels
13
- * - Displays active Tailwind CSS breakpoint (default, sm, md, lg, xl, 2xl)
14
- * - Auto-updates on window resize
15
- * - Only renders in development mode
16
- * - Fixed position in bottom-right corner
17
- *
18
- * @example Next.js
19
- * ```tsx
20
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
21
- * import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
22
- *
23
- * function App() {
24
- * return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
25
- * }
26
- * ```
27
- *
28
- * @example React Router / Vite
29
- * ```tsx
30
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
31
- * import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
32
- *
33
- * function App() {
34
- * return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
35
- * }
36
- * ```
37
- */
38
- export const ViewportInfo = ({ environmentAdapter }) => {
39
- // State to track viewport dimensions
40
- const [{ width: viewportWidth, height: viewportHeight }, setViewportSize] = useState(() => ({
41
- width: 0,
42
- height: 0,
43
- }));
44
- useEffect(() => {
45
- // Guard against SSR - window is not available on the server
46
- if (globalThis.window == undefined) {
47
- return;
48
- }
49
- // Handler to update viewport dimensions
50
- const handleResize = () => {
51
- setViewportSize({
52
- width: window.innerWidth,
53
- height: window.innerHeight,
54
- });
55
- };
56
- // Set initial dimensions
57
- handleResize();
58
- // Listen for resize events
59
- window.addEventListener('resize', handleResize);
60
- // Cleanup listener on unmount
61
- return () => {
62
- window.removeEventListener('resize', handleResize);
63
- };
64
- }, []);
65
- // Only show in development mode
66
- if (!environmentAdapter.isDevelopment())
67
- return null;
68
- return (_jsxs("aside", { className: "fixed bottom-0 right-0 flex items-center gap-x-1 rounded-l-lg px-4 py-2 bg-primary text-primary-foreground font-semibold", children: [_jsx(RulerIcon, { className: "size-5" }), _jsxs("p", { className: "text-lg flex gap-x-2", children: [viewportWidth, "px - ", viewportHeight, "px -", _jsx("span", { className: "inline sm:hidden font-semibold", children: "default" }), _jsx("span", { className: "hidden sm:inline md:hidden font-semibold", children: "sm" }), _jsx("span", { className: "hidden md:inline lg:hidden font-semibold", children: "md" }), _jsx("span", { className: "hidden lg:inline xl:hidden font-semibold", children: "lg " }), _jsx("span", { className: "hidden xl:inline 2xl:hidden font-semibold", children: "xl" }), _jsx("span", { className: "hidden 2xl:inline font-semibold", children: "2xl" })] })] }));
69
- };
@@ -1,42 +0,0 @@
1
- export interface UseHealthcheckOptions {
2
- /** The healthcheck endpoint URL (default: http://localhost:3000/api/healthcheck) */
3
- url?: string;
4
- /** Enable/disable the query (default: true) */
5
- enabled?: boolean;
6
- }
7
- /**
8
- * useHealthcheck hook - Fetches health status from an API endpoint
9
- *
10
- * This hook uses React Query to fetch and cache the health status of your API.
11
- * It's useful for monitoring if your backend is available and responding.
12
- *
13
- * @param options - Configuration options
14
- * @returns React Query result with health status data
15
- *
16
- * @example Basic usage
17
- * ```tsx
18
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
19
- *
20
- * function HealthStatus() {
21
- * const { data, isLoading, error } = useHealthcheck()
22
- *
23
- * if (isLoading) return <div>Checking health...</div>
24
- * if (error) return <div>Health check failed</div>
25
- * return <div>Status: {data?.status}</div>
26
- * }
27
- * ```
28
- *
29
- * @example Custom URL
30
- * ```tsx
31
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
32
- *
33
- * function HealthStatus() {
34
- * const { data } = useHealthcheck({
35
- * url: 'http://localhost:8080/health'
36
- * })
37
- * return <div>{data?.status}</div>
38
- * }
39
- * ```
40
- */
41
- export declare const useHealthcheck: (options?: UseHealthcheckOptions) => import("@tanstack/react-query").UseQueryResult<any, Error>;
42
- //# sourceMappingURL=use-healthcheck.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-healthcheck.d.ts","sourceRoot":"","sources":["../../src/hooks/use-healthcheck.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,GAAI,UAAS,qBAA0B,+DAkBjE,CAAA"}
@@ -1,53 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- /**
3
- * useHealthcheck hook - Fetches health status from an API endpoint
4
- *
5
- * This hook uses React Query to fetch and cache the health status of your API.
6
- * It's useful for monitoring if your backend is available and responding.
7
- *
8
- * @param options - Configuration options
9
- * @returns React Query result with health status data
10
- *
11
- * @example Basic usage
12
- * ```tsx
13
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
14
- *
15
- * function HealthStatus() {
16
- * const { data, isLoading, error } = useHealthcheck()
17
- *
18
- * if (isLoading) return <div>Checking health...</div>
19
- * if (error) return <div>Health check failed</div>
20
- * return <div>Status: {data?.status}</div>
21
- * }
22
- * ```
23
- *
24
- * @example Custom URL
25
- * ```tsx
26
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
27
- *
28
- * function HealthStatus() {
29
- * const { data } = useHealthcheck({
30
- * url: 'http://localhost:8080/health'
31
- * })
32
- * return <div>{data?.status}</div>
33
- * }
34
- * ```
35
- */
36
- export const useHealthcheck = (options = {}) => {
37
- const { url = 'http://localhost:3000/api/healthcheck', enabled = true } = options;
38
- return useQuery({
39
- queryKey: ['healthcheck', url],
40
- queryFn: async () => {
41
- const response = await fetch(url);
42
- if (!response.ok) {
43
- throw new Error(`Health check failed: ${response.statusText}`);
44
- }
45
- return await response.json();
46
- },
47
- enabled,
48
- // Refetch every 30 seconds to keep health status fresh
49
- refetchInterval: 30000,
50
- // Retry failed requests
51
- retry: 3,
52
- });
53
- };
@@ -1,71 +0,0 @@
1
- /**
2
- * Environment detection utilities
3
- *
4
- * These utilities help detect the runtime environment (development, production, server, client).
5
- * They work across different frameworks by checking both process.env and import.meta.env.
6
- */
7
- /**
8
- * Check if running in development mode
9
- * Works with both Next.js (process.env) and Vite (import.meta.env)
10
- *
11
- * @returns true if in development mode
12
- *
13
- * @example
14
- * ```tsx
15
- * import { isDevelopment } from '@teo-garcia/react-shared/utils'
16
- *
17
- * if (isDevelopment()) {
18
- * console.log('Running in dev mode')
19
- * }
20
- * ```
21
- */
22
- export declare const isDevelopment: () => boolean;
23
- /**
24
- * Check if running in production mode
25
- * Works with both Next.js (process.env) and Vite (import.meta.env)
26
- *
27
- * @returns true if in production mode
28
- *
29
- * @example
30
- * ```tsx
31
- * import { isProduction } from '@teo-garcia/react-shared/utils'
32
- *
33
- * if (isProduction()) {
34
- * // Enable analytics
35
- * }
36
- * ```
37
- */
38
- export declare const isProduction: () => boolean;
39
- /**
40
- * Check if code is running on the server (SSR)
41
- * Works by detecting the absence of window object
42
- *
43
- * @returns true if running on server
44
- *
45
- * @example
46
- * ```tsx
47
- * import { isServer } from '@teo-garcia/react-shared/utils'
48
- *
49
- * if (isServer()) {
50
- * // Server-only code
51
- * }
52
- * ```
53
- */
54
- export declare const isServer: () => boolean;
55
- /**
56
- * Check if code is running on the client (browser)
57
- * Works by detecting the presence of window object
58
- *
59
- * @returns true if running on client
60
- *
61
- * @example
62
- * ```tsx
63
- * import { isClient } from '@teo-garcia/react-shared/utils'
64
- *
65
- * if (isClient()) {
66
- * // Client-only code like localStorage access
67
- * }
68
- * ```
69
- */
70
- export declare const isClient: () => boolean;
71
- //# sourceMappingURL=environment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,QAAO,OAYhC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,QAAO,OAE/B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAA"}
@@ -1,86 +0,0 @@
1
- /**
2
- * Environment detection utilities
3
- *
4
- * These utilities help detect the runtime environment (development, production, server, client).
5
- * They work across different frameworks by checking both process.env and import.meta.env.
6
- */
7
- /**
8
- * Check if running in development mode
9
- * Works with both Next.js (process.env) and Vite (import.meta.env)
10
- *
11
- * @returns true if in development mode
12
- *
13
- * @example
14
- * ```tsx
15
- * import { isDevelopment } from '@teo-garcia/react-shared/utils'
16
- *
17
- * if (isDevelopment()) {
18
- * console.log('Running in dev mode')
19
- * }
20
- * ```
21
- */
22
- export const isDevelopment = () => {
23
- // Check process.env first (Next.js, Node.js)
24
- if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
25
- return true;
26
- }
27
- // Check import.meta.env (Vite, modern bundlers)
28
- if (typeof import.meta !== 'undefined' && import.meta.env?.DEV === true) {
29
- return true;
30
- }
31
- return false;
32
- };
33
- /**
34
- * Check if running in production mode
35
- * Works with both Next.js (process.env) and Vite (import.meta.env)
36
- *
37
- * @returns true if in production mode
38
- *
39
- * @example
40
- * ```tsx
41
- * import { isProduction } from '@teo-garcia/react-shared/utils'
42
- *
43
- * if (isProduction()) {
44
- * // Enable analytics
45
- * }
46
- * ```
47
- */
48
- export const isProduction = () => {
49
- return !isDevelopment();
50
- };
51
- /**
52
- * Check if code is running on the server (SSR)
53
- * Works by detecting the absence of window object
54
- *
55
- * @returns true if running on server
56
- *
57
- * @example
58
- * ```tsx
59
- * import { isServer } from '@teo-garcia/react-shared/utils'
60
- *
61
- * if (isServer()) {
62
- * // Server-only code
63
- * }
64
- * ```
65
- */
66
- export const isServer = () => {
67
- return typeof window === 'undefined';
68
- };
69
- /**
70
- * Check if code is running on the client (browser)
71
- * Works by detecting the presence of window object
72
- *
73
- * @returns true if running on client
74
- *
75
- * @example
76
- * ```tsx
77
- * import { isClient } from '@teo-garcia/react-shared/utils'
78
- *
79
- * if (isClient()) {
80
- * // Client-only code like localStorage access
81
- * }
82
- * ```
83
- */
84
- export const isClient = () => {
85
- return !isServer();
86
- };
@@ -1,54 +0,0 @@
1
- /**
2
- * Mock Service Worker (MSW) setup utilities
3
- *
4
- * These utilities help set up MSW for API mocking in development and testing.
5
- * They provide consistent factories for creating MSW workers across projects.
6
- */
7
- import type { RequestHandler } from 'msw';
8
- /**
9
- * Creates and starts a browser MSW worker
10
- * Use this in client-side applications (Next.js, React Router, etc.)
11
- *
12
- * @param handlers - Array of request handlers to use
13
- * @param options - MSW worker options
14
- * @returns Promise that resolves when worker is started
15
- *
16
- * @example
17
- * ```tsx
18
- * import { setupMSWBrowser } from '@teo-garcia/react-shared/utils'
19
- * import { handlers } from './handlers'
20
- *
21
- * // In your app initialization
22
- * if (isDevelopment()) {
23
- * await setupMSWBrowser(handlers)
24
- * }
25
- * ```
26
- */
27
- export declare const setupMSWBrowser: (handlers: RequestHandler[], options?: {
28
- onUnhandledRequest?: "bypass" | "warn" | "error";
29
- }) => Promise<import("msw/browser").SetupWorker>;
30
- /**
31
- * Creates and starts a Node.js MSW server
32
- * Use this in server-side applications and tests
33
- *
34
- * @param handlers - Array of request handlers to use
35
- * @param options - MSW server options
36
- * @returns Promise that resolves to the server instance
37
- *
38
- * @example
39
- * ```tsx
40
- * import { setupMSWServer } from '@teo-garcia/react-shared/utils'
41
- * import { handlers } from './handlers'
42
- *
43
- * // In your test setup
44
- * const server = await setupMSWServer(handlers)
45
- *
46
- * beforeAll(() => server.listen())
47
- * afterEach(() => server.resetHandlers())
48
- * afterAll(() => server.close())
49
- * ```
50
- */
51
- export declare const setupMSWServer: (handlers: RequestHandler[], options?: {
52
- onUnhandledRequest?: "bypass" | "warn" | "error";
53
- }) => Promise<import("msw/node").SetupServerApi>;
54
- //# sourceMappingURL=msw.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msw.d.ts","sourceRoot":"","sources":["../../src/utils/msw.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,cAAc,EAAE,EAC1B,UAAU;IAAE,kBAAkB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,+CAU/D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,cAAc,EAAE,EAC1B,UAAU;IAAE,kBAAkB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,+CAU/D,CAAA"}
package/dist/utils/msw.js DELETED
@@ -1,62 +0,0 @@
1
- /**
2
- * Mock Service Worker (MSW) setup utilities
3
- *
4
- * These utilities help set up MSW for API mocking in development and testing.
5
- * They provide consistent factories for creating MSW workers across projects.
6
- */
7
- /**
8
- * Creates and starts a browser MSW worker
9
- * Use this in client-side applications (Next.js, React Router, etc.)
10
- *
11
- * @param handlers - Array of request handlers to use
12
- * @param options - MSW worker options
13
- * @returns Promise that resolves when worker is started
14
- *
15
- * @example
16
- * ```tsx
17
- * import { setupMSWBrowser } from '@teo-garcia/react-shared/utils'
18
- * import { handlers } from './handlers'
19
- *
20
- * // In your app initialization
21
- * if (isDevelopment()) {
22
- * await setupMSWBrowser(handlers)
23
- * }
24
- * ```
25
- */
26
- export const setupMSWBrowser = async (handlers, options) => {
27
- const { setupWorker } = await import('msw/browser');
28
- const worker = setupWorker(...handlers);
29
- await worker.start({
30
- onUnhandledRequest: options?.onUnhandledRequest ?? 'bypass',
31
- });
32
- return worker;
33
- };
34
- /**
35
- * Creates and starts a Node.js MSW server
36
- * Use this in server-side applications and tests
37
- *
38
- * @param handlers - Array of request handlers to use
39
- * @param options - MSW server options
40
- * @returns Promise that resolves to the server instance
41
- *
42
- * @example
43
- * ```tsx
44
- * import { setupMSWServer } from '@teo-garcia/react-shared/utils'
45
- * import { handlers } from './handlers'
46
- *
47
- * // In your test setup
48
- * const server = await setupMSWServer(handlers)
49
- *
50
- * beforeAll(() => server.listen())
51
- * afterEach(() => server.resetHandlers())
52
- * afterAll(() => server.close())
53
- * ```
54
- */
55
- export const setupMSWServer = async (handlers, options) => {
56
- const { setupServer } = await import('msw/node');
57
- const server = setupServer(...handlers);
58
- server.listen({
59
- onUnhandledRequest: options?.onUnhandledRequest ?? 'bypass',
60
- });
61
- return server;
62
- };