@intrig/react 0.0.1 → 1.0.2

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/README.md CHANGED
@@ -1,82 +1,33 @@
1
1
  # Intrig
2
2
 
3
- <a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
3
+ Intrig is a powerful tool for simplifying API integration in React applications. It provides enhanced documentation, API version management, and developer tooling for seamless frontend-backend integration.
4
4
 
5
- Your new, shiny [Nx workspace](https://nx.dev) is almost ready ✨.
5
+ ## Getting Started
6
6
 
7
- [Learn more about this workspace setup and its capabilities](https://nx.dev/nx-api/node?utm_source=nx_project&amp;utm_medium=readme&amp;utm_campaign=nx_projects) or run `npx nx graph` to visually explore what was created. Now, let's get you up to speed!
7
+ Prerequisites
8
8
 
9
- ## Finish your CI setup
9
+ * Node.js v16+.
10
+ * Nx build tool.
10
11
 
11
- [Click here to finish setting up your workspace!](https://cloud.nx.app/connect/e4mOmAhulO)
12
+ ## Installation
12
13
 
14
+ Clone the repository and install dependencies:
13
15
 
14
- ## Run tasks
16
+ ```bash
17
+ $ git clone https://github.com/your-username/intrig.git
18
+ $ cd intrig
19
+ $ npm install
15
20
 
16
- To run the dev server for your app, use:
17
-
18
- ```sh
19
- npx nx serve intrig
20
- ```
21
-
22
- To create a production bundle:
23
-
24
- ```sh
25
- npx nx build intrig
26
- ```
27
-
28
- To see all available targets to run for a project, run:
29
-
30
- ```sh
31
- npx nx show project intrig
32
21
  ```
33
22
 
34
- These targets are either [inferred automatically](https://nx.dev/concepts/inferred-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or defined in the `project.json` or `package.json` files.
35
-
36
- [More about running tasks in the docs &raquo;](https://nx.dev/features/run-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
37
-
38
- ## Add new projects
39
-
40
- While you could add new projects to your workspace manually, you might want to leverage [Nx plugins](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) and their [code generation](https://nx.dev/features/generate-code?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) feature.
41
-
42
- Use the plugin's generator to create new projects.
43
-
44
- To generate a new application, use:
45
-
46
- ```sh
47
- npx nx g @nx/node:app demo
48
- ```
49
-
50
- To generate a new library, use:
51
-
52
- ```sh
53
- npx nx g @nx/node:lib mylib
54
- ```
55
-
56
- You can use `npx nx list` to get a list of installed plugins. Then, run `npx nx list <plugin-name>` to learn about more specific capabilities of a particular plugin. Alternatively, [install Nx Console](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) to browse plugins and generators in your IDE.
57
-
58
- [Learn more about Nx plugins &raquo;](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) | [Browse the plugin registry &raquo;](https://nx.dev/plugin-registry?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
59
-
60
-
61
- [Learn more about Nx on CI](https://nx.dev/ci/intro/ci-with-nx#ready-get-started-with-your-provider?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
62
-
63
- ## Install Nx Console
64
-
65
- Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.
23
+ ## License
66
24
 
67
- [Install Nx Console &raquo;](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
25
+ Intrig is open source software licensed under the [MIT License](LICENSE).
68
26
 
69
- ## Useful links
27
+ ## Contribution
70
28
 
71
- Learn more:
29
+ We welcome contributions! Please read our [contributing guide](CONTRIBUTING.md) to learn how you can get involved.
72
30
 
73
- - [Learn more about this workspace setup](https://nx.dev/nx-api/node?utm_source=nx_project&amp;utm_medium=readme&amp;utm_campaign=nx_projects)
74
- - [Learn about Nx on CI](https://nx.dev/ci/intro/ci-with-nx?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
75
- - [Releasing Packages with Nx release](https://nx.dev/features/manage-releases?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
76
- - [What are Nx plugins?](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
31
+ ## Contact
77
32
 
78
- And join the Nx community:
79
- - [Discord](https://go.nx.dev/community)
80
- - [Follow us on X](https://twitter.com/nxdevtools) or [LinkedIn](https://www.linkedin.com/company/nrwl)
81
- - [Our Youtube channel](https://www.youtube.com/@nxdevtools)
82
- - [Our blog](https://nx.dev/blog?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
33
+ For questions or feedback, feel free to reach out at [support@intrigsoft.com](mailto\:support@intrigsoft.com).
package/index.esm.js CHANGED
@@ -3093,6 +3093,73 @@ function validationError(error) {
3093
3093
  function isValidationError(value) {
3094
3094
  return value.state === 'validation-error';
3095
3095
  }
3096
+ /**
3097
+ * Constructs a network error object.
3098
+ *
3099
+ * @param error The error object corresponding to the network request.
3100
+ * @param statusCode A string representing the HTTP status code returned.
3101
+ * @param request The request object associated with the network operation.
3102
+ * @return A NetworkError object containing the error type, status code, error details, and the original request.
3103
+ */
3104
+ function networkError(error, statusCode, request) {
3105
+ return {
3106
+ type: 'network',
3107
+ statusCode,
3108
+ error,
3109
+ request
3110
+ };
3111
+ }
3112
+ /**
3113
+ * Determines if the provided IntrigError is of type 'network'.
3114
+ *
3115
+ * @param {IntrigError<T, E>} value - The error value to check the type of.
3116
+ * @return {boolean} - Returns true if the error is of type 'network', otherwise false.
3117
+ */
3118
+ function isNetworkError(value) {
3119
+ return value.type === 'network';
3120
+ }
3121
+ /**
3122
+ * Constructs a RequestValidationError object encapsulating the ZodError.
3123
+ *
3124
+ * @param {ZodError} error - The error object resulting from Zod schema validation.
3125
+ * @return {RequestValidationError<T, E>} A RequestValidationError object containing the validation error information.
3126
+ */
3127
+ function requestValidationError(error) {
3128
+ return {
3129
+ type: 'request-validation',
3130
+ error
3131
+ };
3132
+ }
3133
+ /**
3134
+ * Determines if a given error is of type RequestValidationError.
3135
+ *
3136
+ * @param value The error object to check, which implements the IntrigError interface.
3137
+ * @return A boolean indicating whether the error is a RequestValidationError.
3138
+ */
3139
+ function isRequestValidationError(value) {
3140
+ return value.type === 'request-validation';
3141
+ }
3142
+ /**
3143
+ * Constructs a ResponseValidationError object with a specified error.
3144
+ *
3145
+ * @param {ZodError} error - The validation error encountered during response validation.
3146
+ * @return {ResponseValidationError<T, E>} An error object containing the type of error and the validation error details.
3147
+ */
3148
+ function responseValidationError(error) {
3149
+ return {
3150
+ type: 'response-validation',
3151
+ error
3152
+ };
3153
+ }
3154
+ /**
3155
+ * Determines if the given error is a response validation error.
3156
+ *
3157
+ * @param {IntrigError<T, E>} value - The error object to assess.
3158
+ * @return {boolean} True if the error is a response validation error, otherwise false.
3159
+ */
3160
+ function isResponseValidationError(value) {
3161
+ return value.type === 'response-validation';
3162
+ }
3096
3163
 
3097
3164
  /**
3098
3165
  * Context object created using `createContext` function. Provides a way to share state, dispatch functions,
@@ -3140,7 +3207,7 @@ function IntrigProvider({
3140
3207
  return {};
3141
3208
  }, [configs]);
3142
3209
  const contextValue = useMemo(() => {
3143
- async function execute(request, dispatch, schema) {
3210
+ async function execute(request, dispatch, schema, errorSchema) {
3144
3211
  try {
3145
3212
  dispatch(pending());
3146
3213
  let response = await axiosInstances[request.source].request(request);
@@ -3156,13 +3223,22 @@ function IntrigProvider({
3156
3223
  dispatch(success(response.data));
3157
3224
  }
3158
3225
  } else {
3159
- var _response$data;
3160
- dispatch(error((_response$data = response.data) != null ? _response$data : response.statusText, response.status));
3226
+ var _errorSchema$safePars, _response$data, _ref;
3227
+ let {
3228
+ data,
3229
+ error: validationError
3230
+ } = (_errorSchema$safePars = errorSchema == null ? void 0 : errorSchema.safeParse((_response$data = response.data) != null ? _response$data : {})) != null ? _errorSchema$safePars : {};
3231
+ //todo: handle error validation error.
3232
+ dispatch(error((_ref = data != null ? data : response.data) != null ? _ref : response.statusText, response.status));
3161
3233
  }
3162
3234
  } catch (e) {
3163
3235
  if (isAxiosError(e)) {
3164
- var _e$response, _e$response2;
3165
- dispatch(error((_e$response = e.response) == null ? void 0 : _e$response.data, (_e$response2 = e.response) == null ? void 0 : _e$response2.status, request));
3236
+ var _errorSchema$safePars2, _e$response$data, _e$response, _e$response2, _e$response3;
3237
+ let {
3238
+ data,
3239
+ error: validationError
3240
+ } = (_errorSchema$safePars2 = errorSchema == null ? void 0 : errorSchema.safeParse((_e$response$data = (_e$response = e.response) == null ? void 0 : _e$response.data) != null ? _e$response$data : {})) != null ? _errorSchema$safePars2 : {};
3241
+ dispatch(error(data != null ? data : (_e$response2 = e.response) == null ? void 0 : _e$response2.data, (_e$response3 = e.response) == null ? void 0 : _e$response3.status, request));
3166
3242
  } else {
3167
3243
  dispatch(error(e));
3168
3244
  }
@@ -3297,6 +3373,7 @@ function useNetworkState({
3297
3373
  operation,
3298
3374
  source,
3299
3375
  schema,
3376
+ errorSchema,
3300
3377
  debounceDelay: requestDebounceDelay
3301
3378
  }) {
3302
3379
  var _context$state3;
@@ -3315,8 +3392,8 @@ function useNetworkState({
3315
3392
  });
3316
3393
  }, [key, operation, source, context.dispatch]);
3317
3394
  const debounceDelay = useMemo(() => {
3318
- var _ref, _context$configs;
3319
- return (_ref = requestDebounceDelay != null ? requestDebounceDelay : (_context$configs = context.configs) == null ? void 0 : _context$configs.debounceDelay) != null ? _ref : 0;
3395
+ var _ref2, _context$configs;
3396
+ return (_ref2 = requestDebounceDelay != null ? requestDebounceDelay : (_context$configs = context.configs) == null ? void 0 : _context$configs.debounceDelay) != null ? _ref2 : 0;
3320
3397
  }, [context.configs, requestDebounceDelay]);
3321
3398
  const execute = useCallback(async request => {
3322
3399
  let abortController = new AbortController();
@@ -3340,7 +3417,7 @@ function useNetworkState({
3340
3417
  },
3341
3418
  signal: abortController.signal
3342
3419
  });
3343
- await context.execute(requestConfig, dispatch, schema);
3420
+ await context.execute(requestConfig, dispatch, schema, errorSchema);
3344
3421
  }, [networkState, context.dispatch, axios]);
3345
3422
  const deboundedExecute = useMemo(() => debounce(execute, debounceDelay != null ? debounceDelay : 0), [execute]);
3346
3423
  const clear = useCallback(() => {
@@ -3409,4 +3486,4 @@ function useCentralPendingStateHandling() {
3409
3486
  return result;
3410
3487
  }
3411
3488
 
3412
- export { IntrigProvider, IntrigProviderStub, StatusTrap, error, init, isError, isInit, isPending, isSuccess, isSuccessfulDispatch, isValidationError, pending, success, successfulDispatch, useCentralErrorHandling, useCentralPendingStateHandling, useNetworkState, validationError };
3489
+ export { IntrigProvider, IntrigProviderStub, StatusTrap, error, init, isError, isInit, isNetworkError, isPending, isRequestValidationError, isResponseValidationError, isSuccess, isSuccessfulDispatch, isValidationError, networkError, pending, requestValidationError, responseValidationError, success, successfulDispatch, useCentralErrorHandling, useCentralPendingStateHandling, useNetworkState, validationError };
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@intrig/react",
3
- "version": "0.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "private": false,
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./index.mjs",
10
- "require": "./index.js"
9
+ "import": "./src/index.js",
10
+ "types": "./src/index.d.ts"
11
+ },
12
+ "./*": {
13
+ "import": "./src/*.js",
14
+ "types": "./src/*.d.ts"
11
15
  }
12
16
  },
13
17
  "dependencies": {
@@ -28,9 +28,9 @@ interface RequestType<T = any> {
28
28
  export interface ContextType {
29
29
  state: GlobalState;
30
30
  filteredState: GlobalState;
31
- dispatch: React.Dispatch<NetworkAction<unknown>>;
31
+ dispatch: React.Dispatch<NetworkAction<unknown, unknown>>;
32
32
  configs: DefaultConfigs;
33
- execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: ZodSchema<T> | undefined) => Promise<void>;
33
+ execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: ZodSchema<T> | undefined, errorSchema: ZodSchema<T> | undefined) => Promise<void>;
34
34
  }
35
35
  /**
36
36
  * Context object created using `createContext` function. Provides a way to share state, dispatch functions,
@@ -53,6 +53,7 @@ export interface NetworkStateProps<T> {
53
53
  operation: string;
54
54
  source: string;
55
55
  schema?: ZodSchema<T>;
56
+ errorSchema?: ZodSchema<T>;
56
57
  debounceDelay?: number;
57
58
  }
58
59
  /**
@@ -71,11 +72,11 @@ export interface NetworkStateProps<T> {
71
72
  * Returns a state object representing the current network state,
72
73
  * a function to execute the network request, and a function to clear the request.
73
74
  */
74
- export declare function useNetworkState<T>({ key, operation, source, schema, debounceDelay: requestDebounceDelay, }: NetworkStateProps<T>): [
75
- NetworkState<T>,
75
+ export declare function useNetworkState<T, E = unknown>({ key, operation, source, schema, errorSchema, debounceDelay: requestDebounceDelay, }: NetworkStateProps<T>): [
76
+ NetworkState<T, E>,
76
77
  (request: RequestType) => void,
77
78
  clear: () => void,
78
- (state: NetworkState<T>) => void
79
+ (state: NetworkState<T, E>) => void
79
80
  ];
80
81
  /**
81
82
  * Handles central error extraction from the provided context.
@@ -87,7 +88,7 @@ export declare function useCentralErrorHandling(): {
87
88
  operation: string;
88
89
  key: string;
89
90
  state: "error";
90
- error: any;
91
+ error: unknown;
91
92
  statusCode?: number;
92
93
  request?: any;
93
94
  }[];
@@ -97,4 +98,4 @@ export declare function useCentralErrorHandling(): {
97
98
  *
98
99
  * @return {NetworkState} The aggregated network state based on the pending states and their progress.
99
100
  */
100
- export declare function useCentralPendingStateHandling(): NetworkState<unknown>;
101
+ export declare function useCentralPendingStateHandling(): NetworkState<unknown, unknown>;
@@ -1,3 +1,4 @@
1
+ import { ZodError } from 'zod';
1
2
  /**
2
3
  * State of an asynchronous call. Network state follows the state diagram given below.
3
4
  *
@@ -21,31 +22,31 @@
21
22
  *
22
23
  * </pre>
23
24
  */
24
- export interface NetworkState<T = unknown> {
25
+ export interface NetworkState<T = unknown, E = unknown> {
25
26
  state: 'init' | 'pending' | 'success' | 'error';
26
27
  }
27
28
  /**
28
29
  * Network call is not yet started
29
30
  */
30
- export interface InitState<T> extends NetworkState<T> {
31
+ export interface InitState<T, E = unknown> extends NetworkState<T, E> {
31
32
  state: 'init';
32
33
  }
33
34
  /**
34
35
  * Checks whether the state is init state
35
36
  * @param state
36
37
  */
37
- export declare function isInit<T>(state: NetworkState<T>): state is InitState<T>;
38
+ export declare function isInit<T, E = unknown>(state: NetworkState<T, E>): state is InitState<T, E>;
38
39
  /**
39
40
  * Initializes a new state.
40
41
  *
41
42
  * @template T The type of the state.
42
43
  * @return {InitState<T>} An object representing the initial state.
43
44
  */
44
- export declare function init<T>(): InitState<T>;
45
+ export declare function init<T, E = unknown>(): InitState<T, E>;
45
46
  /**
46
47
  * Network call is not yet completed
47
48
  */
48
- export interface PendingState<T> extends NetworkState<T> {
49
+ export interface PendingState<T, E = unknown> extends NetworkState<T, E> {
49
50
  state: 'pending';
50
51
  progress?: Progress;
51
52
  }
@@ -69,17 +70,17 @@ export interface Progress {
69
70
  * Checks whether the state is pending state
70
71
  * @param state
71
72
  */
72
- export declare function isPending<T>(state: NetworkState<T>): state is PendingState<T>;
73
+ export declare function isPending<T, E = unknown>(state: NetworkState<T, E>): state is PendingState<T, E>;
73
74
  /**
74
75
  * Generates a PendingState object with a state of "pending".
75
76
  *
76
77
  * @return {PendingState<T>} An object representing the pending state.
77
78
  */
78
- export declare function pending<T>(progress?: Progress | undefined): PendingState<T>;
79
+ export declare function pending<T, E = unknown>(progress?: Progress | undefined): PendingState<T, E>;
79
80
  /**
80
81
  * Network call is completed with success state
81
82
  */
82
- export interface SuccessState<T> extends NetworkState<T> {
83
+ export interface SuccessState<T, E = unknown> extends NetworkState<T, E> {
83
84
  state: 'success';
84
85
  data: T;
85
86
  }
@@ -87,20 +88,20 @@ export interface SuccessState<T> extends NetworkState<T> {
87
88
  * Checks whether the state is success response
88
89
  * @param state
89
90
  */
90
- export declare function isSuccess<T>(state: NetworkState<T>): state is SuccessState<T>;
91
+ export declare function isSuccess<T, E = unknown>(state: NetworkState<T, E>): state is SuccessState<T, E>;
91
92
  /**
92
93
  * Creates a success state object with the provided data.
93
94
  *
94
95
  * @param {T} data - The data to be included in the success state.
95
96
  * @return {SuccessState<T>} An object representing a success state containing the provided data.
96
97
  */
97
- export declare function success<T>(data: T): SuccessState<T>;
98
+ export declare function success<T, E = unknown>(data: T): SuccessState<T, E>;
98
99
  /**
99
100
  * Network call is completed with error response
100
101
  */
101
- export interface ErrorState<T> extends NetworkState<T> {
102
+ export interface ErrorState<T, E = unknown> extends NetworkState<T, E> {
102
103
  state: 'error';
103
- error: any;
104
+ error: E;
104
105
  statusCode?: number;
105
106
  request?: any;
106
107
  }
@@ -108,7 +109,7 @@ export interface ErrorState<T> extends NetworkState<T> {
108
109
  * Checks whether the state is error state
109
110
  * @param state
110
111
  */
111
- export declare function isError<T>(state: NetworkState<T>): state is ErrorState<T>;
112
+ export declare function isError<T, E = unknown>(state: NetworkState<T, E>): state is ErrorState<T, E>;
112
113
  /**
113
114
  * Constructs an ErrorState object representing an error.
114
115
  *
@@ -116,7 +117,7 @@ export declare function isError<T>(state: NetworkState<T>): state is ErrorState<
116
117
  * @param {string} [statusCode] - An optional status code associated with the error.
117
118
  * @return {ErrorState<T>} An object representing the error state.
118
119
  */
119
- export declare function error<T>(error: any, statusCode?: number, request?: any): ErrorState<T>;
120
+ export declare function error<T, E = unknown>(error: E, statusCode?: number, request?: any): ErrorState<T>;
120
121
  /**
121
122
  * Represents an error state with additional contextual information.
122
123
  *
@@ -128,7 +129,7 @@ export declare function error<T>(error: any, statusCode?: number, request?: any)
128
129
  * @property {string} operation - The operation being performed when the error occurred.
129
130
  * @property {string} key - A unique key identifying the specific error instance.
130
131
  */
131
- export interface ErrorWithContext<T = unknown> extends ErrorState<T> {
132
+ export interface ErrorWithContext<T = unknown, E = unknown> extends ErrorState<T, E> {
132
133
  source: string;
133
134
  operation: string;
134
135
  key: string;
@@ -141,24 +142,24 @@ export interface ErrorWithContext<T = unknown> extends ErrorState<T> {
141
142
  * @property {NetworkState<any>} state - The current state of the network action
142
143
  * @property {string} key - The unique identifier for the network action
143
144
  */
144
- export interface NetworkAction<T> {
145
+ export interface NetworkAction<T, E> {
145
146
  key: string;
146
147
  source: string;
147
148
  operation: string;
148
- state: NetworkState<T>;
149
+ state: NetworkState<T, E>;
149
150
  handled?: boolean;
150
151
  }
151
152
  type HookWithKey = {
152
153
  key: string;
153
154
  };
154
- export type DeleteHook<P> = ((key?: string) => [NetworkState<never>, (params: P) => void, () => void]) & HookWithKey;
155
- export type DeleteHookOp<P> = ((key?: string) => [NetworkState<never>, (params?: P) => void, () => void]) & HookWithKey;
156
- export type GetHook<P, T> = ((key?: string) => [NetworkState<T>, (params: P) => void, () => void]) & HookWithKey;
157
- export type GetHookOp<P, T> = ((key?: string) => [NetworkState<T>, (params?: P) => void, () => void]) & HookWithKey;
158
- export type PostHook<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params: P) => void, () => void]) & HookWithKey;
159
- export type PostHookOp<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params?: P) => void, () => void]) & HookWithKey;
160
- export type PutHook<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params: P) => void, () => void]) & HookWithKey;
161
- export type PutHookOp<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params?: P) => void, () => void]) & HookWithKey;
155
+ export type DeleteHook<P, E = unknown> = ((key?: string) => [NetworkState<never, E>, (params: P) => void, () => void]) & HookWithKey;
156
+ export type DeleteHookOp<P, E = unknown> = ((key?: string) => [NetworkState<never, E>, (params?: P) => void, () => void]) & HookWithKey;
157
+ export type GetHook<P, T, E = unknown> = ((key?: string) => [NetworkState<T, E>, (params: P) => void, () => void]) & HookWithKey;
158
+ export type GetHookOp<P, T, E = unknown> = ((key?: string) => [NetworkState<T, E>, (params?: P) => void, () => void]) & HookWithKey;
159
+ export type PostHook<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params: P) => void, () => void]) & HookWithKey;
160
+ export type PostHookOp<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params?: P) => void, () => void]) & HookWithKey;
161
+ export type PutHook<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params: P) => void, () => void]) & HookWithKey;
162
+ export type PutHookOp<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params?: P) => void, () => void]) & HookWithKey;
162
163
  export type IntrigHook<P = undefined, B = undefined, T = any> = DeleteHook<P> | GetHook<P, T> | PostHook<P, T, B> | PutHook<P, T, B> | PostHookOp<P, T, B> | PutHookOp<P, T, B> | GetHookOp<P, T> | DeleteHookOp<P>;
163
164
  /**
164
165
  * Represents the dispatch state of a process.
@@ -220,4 +221,111 @@ export declare function validationError<T>(error: any): ValidationError<T>;
220
221
  * @return {boolean} - Returns true if the provided DispatchState object is a ValidationError, otherwise returns false.
221
222
  */
222
223
  export declare function isValidationError<T>(value: DispatchState<T>): value is ValidationError<T>;
224
+ /**
225
+ * Represents an error structure with a specified type and associated data.
226
+ *
227
+ * @template T - The type of the data associated with the error.
228
+ * @template E - The type of the error detail.
229
+ *
230
+ * @property {string} type - A string representing the type of the error.
231
+ */
232
+ export interface IntrigError<T, E> {
233
+ type: string;
234
+ }
235
+ /**
236
+ * Represents an error encountered during a network operation.
237
+ * Extends from the `IntrigError` interface, adding network-specific properties.
238
+ *
239
+ * @template T - The type of the intrinsic data associated with the error.
240
+ * @template E - The type of the error details, defaulting to `unknown`.
241
+ *
242
+ * @property {string} type - A constant property representing the error type, always set to 'network'.
243
+ * @property {string} statusCode - A string representation of the HTTP status code associated with the error, indicating the nature of the network failure.
244
+ * @property {E} error - The detailed error information specific to the failure, type extends from the generic E, allowing flexibility in the error details.
245
+ * @property {any} request - The request object that was attempted when the network error occurred, providing context for what operation failed.
246
+ */
247
+ export interface NetworkError<T, E = unknown> extends IntrigError<T, E> {
248
+ type: 'network';
249
+ statusCode: string;
250
+ error: E;
251
+ request: any;
252
+ }
253
+ /**
254
+ * Constructs a network error object.
255
+ *
256
+ * @param error The error object corresponding to the network request.
257
+ * @param statusCode A string representing the HTTP status code returned.
258
+ * @param request The request object associated with the network operation.
259
+ * @return A NetworkError object containing the error type, status code, error details, and the original request.
260
+ */
261
+ export declare function networkError<T, E>(error: E, statusCode: string, request: any): NetworkError<T, E>;
262
+ /**
263
+ * Determines if the provided IntrigError is of type 'network'.
264
+ *
265
+ * @param {IntrigError<T, E>} value - The error value to check the type of.
266
+ * @return {boolean} - Returns true if the error is of type 'network', otherwise false.
267
+ */
268
+ export declare function isNetworkError<T, E>(value: IntrigError<T, E>): value is NetworkError<T, E>;
269
+ /**
270
+ * Interface representing a request validation error.
271
+ *
272
+ * This error occurs when a validation process on a request fails. It extends the IntrigError interface
273
+ * by adding specific properties related to request validation.
274
+ *
275
+ * @template T - The type of the data associated with the error.
276
+ * @template E - The optional type of additional error information. Defaults to unknown.
277
+ *
278
+ * @extends IntrigError<T, E>
279
+ *
280
+ * @property {string} type - A string literal indicating the error type as 'request-validation'.
281
+ * @property {ZodError} error - An instance of ZodError containing detailed validation error information.
282
+ */
283
+ export interface RequestValidationError<T, E = unknown> extends IntrigError<T, E> {
284
+ type: 'request-validation';
285
+ error: ZodError;
286
+ }
287
+ /**
288
+ * Constructs a RequestValidationError object encapsulating the ZodError.
289
+ *
290
+ * @param {ZodError} error - The error object resulting from Zod schema validation.
291
+ * @return {RequestValidationError<T, E>} A RequestValidationError object containing the validation error information.
292
+ */
293
+ export declare function requestValidationError<T, E>(error: ZodError): RequestValidationError<T, E>;
294
+ /**
295
+ * Determines if a given error is of type RequestValidationError.
296
+ *
297
+ * @param value The error object to check, which implements the IntrigError interface.
298
+ * @return A boolean indicating whether the error is a RequestValidationError.
299
+ */
300
+ export declare function isRequestValidationError<T, E>(value: IntrigError<T, E>): value is RequestValidationError<T, E>;
301
+ /**
302
+ * ResponseValidationError interface is designed to extend the capabilities of the IntrigError interface,
303
+ * specifically for handling errors related to response validation.
304
+ *
305
+ * @template T - Represents the type of the data or payload associated with the error.
306
+ * @template E - Represents the type of any additional error information. Defaults to unknown.
307
+ *
308
+ * @extends IntrigError
309
+ *
310
+ * @property type - A string literal that identifies the type of error as 'response-validation'.
311
+ * @property error - An instance of ZodError representing the validation error encountered.
312
+ */
313
+ export interface ResponseValidationError<T, E = unknown> extends IntrigError<T, E> {
314
+ type: 'response-validation';
315
+ error: ZodError;
316
+ }
317
+ /**
318
+ * Constructs a ResponseValidationError object with a specified error.
319
+ *
320
+ * @param {ZodError} error - The validation error encountered during response validation.
321
+ * @return {ResponseValidationError<T, E>} An error object containing the type of error and the validation error details.
322
+ */
323
+ export declare function responseValidationError<T, E>(error: ZodError): ResponseValidationError<T, E>;
324
+ /**
325
+ * Determines if the given error is a response validation error.
326
+ *
327
+ * @param {IntrigError<T, E>} value - The error object to assess.
328
+ * @return {boolean} True if the error is a response validation error, otherwise false.
329
+ */
330
+ export declare function isResponseValidationError<T, E>(value: IntrigError<T, E>): value is ResponseValidationError<T, E>;
223
331
  export {};