@next-feature/client 0.1.3-0 → 0.1.3-1

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/index.js CHANGED
@@ -162,7 +162,7 @@ class c {
162
162
  /**
163
163
  * Get the underlying Axios instance for advanced usage
164
164
  */
165
- getAxiosInstance() {
165
+ get axios() {
166
166
  return this.instance;
167
167
  }
168
168
  }
@@ -4,4 +4,5 @@ interface WithApiOptions<T> {
4
4
  successMessage?: string;
5
5
  }
6
6
  export declare function withApi<F extends (...args: any[]) => Promise<any>>(fn: F, options?: WithApiOptions<Awaited<ReturnType<F>>>): (...args: Parameters<F>) => Promise<ApiResponse<Awaited<ReturnType<F>>>>;
7
+ export declare function withForm<State>(fn: (formData: FormData) => Promise<ApiResponse<State>>): (prevState: Awaited<ApiResponse<State>>, formData: FormData) => Promise<ApiResponse<State>>;
7
8
  export {};
package/lib/client.d.ts CHANGED
@@ -68,5 +68,5 @@ export declare class ApiClient {
68
68
  /**
69
69
  * Get the underlying Axios instance for advanced usage
70
70
  */
71
- getAxiosInstance(): AxiosInstance;
71
+ get axios(): AxiosInstance;
72
72
  }
@@ -1,4 +1,5 @@
1
1
  import { HttpStatusCode } from 'axios';
2
+ import { ApiError } from '../error';
2
3
  /**
3
4
  * [api-response]
4
5
  * next-feature@0.0.11-beta
@@ -7,7 +8,7 @@ import { HttpStatusCode } from 'axios';
7
8
  export interface ApiResponse<Response> {
8
9
  success?: boolean;
9
10
  message?: string;
10
- error?: ProblemDetail;
11
+ error?: ApiError;
11
12
  data: Response;
12
13
  }
13
14
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-feature/client",
3
- "version": "0.1.3-0",
3
+ "version": "0.1.3-1",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
package/server.js CHANGED
@@ -1,29 +1,36 @@
1
1
  import { A as o } from "./error-DRDfrCQN.js";
2
- function u(r, c) {
3
- const e = {
2
+ function u(e, r) {
3
+ const a = {
4
4
  fallbackData: {},
5
5
  successMessage: "success",
6
- ...c
6
+ ...r
7
7
  };
8
- return async (...t) => {
8
+ return async (...s) => {
9
9
  try {
10
- const s = await r(...t);
10
+ const t = await e(...s);
11
11
  return {
12
12
  success: !0,
13
- message: e.successMessage,
14
- data: s
13
+ message: a.successMessage,
14
+ data: t
15
15
  };
16
- } catch (s) {
17
- const a = o.of(s);
16
+ } catch (t) {
17
+ const c = o.of(t);
18
18
  return {
19
- data: e.fallbackData,
20
- error: a.body,
21
- message: a.message,
19
+ data: a.fallbackData,
20
+ error: c,
21
+ message: c.message,
22
22
  success: !1
23
23
  };
24
24
  }
25
25
  };
26
26
  }
27
+ function i(e) {
28
+ return async (r, a) => {
29
+ const s = await e(a);
30
+ return s.error || !s.success ? { ...s, data: r.data } : s;
31
+ };
32
+ }
27
33
  export {
28
- u as withApi
34
+ u as withApi,
35
+ i as withForm
29
36
  };