@ryneex/api-client 0.0.51 → 1.0.0-beta.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 (4) hide show
  1. package/README.md +369 -7
  2. package/index.d.ts +42 -28
  3. package/index.js +83 -73
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -1,15 +1,377 @@
1
- # api-client
1
+ # @ryneex/api-client
2
2
 
3
- To install dependencies:
3
+ Type-safe API client built on **Axios**, **Zod**, and **TanStack Query**. Define endpoints with request/response validation and get ready-to-use `call`, `queryOptions`, and `mutationOptions` for React Query.
4
+
5
+ ---
6
+
7
+ ## Installation
4
8
 
5
9
  ```bash
6
- bun install
10
+ bun add @ryneex/api-client axios zod @tanstack/react-query
11
+ # or
12
+ npm i @ryneex/api-client axios zod @tanstack/react-query
7
13
  ```
8
14
 
9
- To run:
15
+ **Peer dependencies:** `axios` ^1.13.2, `zod` ^4, `@tanstack/react-query` ^5, `typescript` ^5.
10
16
 
11
- ```bash
12
- bun run src/index.ts
17
+ ---
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import axios from "axios";
23
+ import z from "zod";
24
+ import { createClient } from "@ryneex/api-client";
25
+
26
+ const axiosInstance = axios.create({
27
+ baseURL: "https://api.example.com",
28
+ headers: { "Content-Type": "application/json" },
29
+ });
30
+
31
+ const client = createClient(axiosInstance);
32
+
33
+ // Define a GET endpoint with validated response
34
+ const getUsers = client.create({
35
+ method: "GET",
36
+ path: "/users",
37
+ outputSchema: z.object({
38
+ users: z.array(
39
+ z.object({ id: z.string(), name: z.string(), email: z.string() }),
40
+ ),
41
+ }),
42
+ });
43
+
44
+ // Call it (returns AxiosResponse<inferred output type>)
45
+ const res = await getUsers();
46
+ console.log(res.data.users);
47
+
48
+ // Or use with React Query
49
+ import { useQuery } from "@tanstack/react-query";
50
+ const { data } = useQuery(getUsers.queryOptions());
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Creating the client
56
+
57
+ Use any **Axios instance** (with base URL, auth, interceptors, etc.) with `createClient`:
58
+
59
+ ```ts
60
+ import axios from "axios";
61
+ import { createClient } from "@ryneex/api-client";
62
+
63
+ const axiosInstance = axios.create({
64
+ baseURL: "https://api.example.com/v1",
65
+ timeout: 10_000,
66
+ headers: {
67
+ "Content-Type": "application/json",
68
+ Authorization: `Bearer ${process.env.API_TOKEN}`,
69
+ },
70
+ });
71
+
72
+ const client = createClient(axiosInstance);
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Defining endpoints: `client.create`
78
+
79
+ `client.create` takes:
80
+
81
+ | Option | Type | Required | Description |
82
+ | ----------------- | --------------------------------------- | -------- | -------------------------------------------------- |
83
+ | `method` | `GET \| POST \| PUT \| PATCH \| DELETE` | Yes | HTTP method. |
84
+ | `path` | `string \| (data) => string` | Yes | URL path (static or derived from input/variables). |
85
+ | `outputSchema` | `z.ZodType` | Yes | Zod schema for response body; type is inferred. |
86
+ | `inputSchema` | `z.ZodType` | No | Schema for `data.input` (e.g. body for POST). |
87
+ | `variablesSchema` | `z.ZodType` | No | Schema for `data.variables` (e.g. path/query). |
88
+ | `axiosOptions` | `(data) => AxiosRequestConfig` | No | Extra Axios config (headers, params, data, etc.). |
89
+ | `transform` | `(data, payload) => TOutput` | No | Optional post-processing of parsed response data. |
90
+
91
+ The returned endpoint is a **callable function** with helpers:
92
+
93
+ - **Direct call** — call `await endpoint(payload?)` to perform the request; returns `Promise<AxiosResponse<TOutput>>`.
94
+ - **`queryOptions(opts?)`** — `UseQueryOptions` for `useQuery`.
95
+ - **`mutationOptions(opts?)`** — `UseMutationOptions` for `useMutation`.
96
+ - **`config`** — `{ method, path, outputSchema, inputSchema?, variablesSchema? }`.
97
+
98
+ ---
99
+
100
+ ## Example: GET with no input
101
+
102
+ ```ts
103
+ const getProducts = client.create({
104
+ method: "GET",
105
+ path: "/products",
106
+ outputSchema: z.object({
107
+ products: z.array(
108
+ z.object({
109
+ id: z.string(),
110
+ title: z.string(),
111
+ price: z.number(),
112
+ }),
113
+ ),
114
+ }),
115
+ });
116
+
117
+ // Direct call
118
+ const { data } = await getProducts();
119
+ // data is { products: { id, title, price }[] }
120
+
121
+ // React Query
122
+ const { data } = useQuery(getProducts.queryOptions());
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Example: GET with variables (path/query)
128
+
129
+ Use `variablesSchema` and a **path function** when the URL or query depends on parameters:
130
+
131
+ ```ts
132
+ const getUserById = client.create({
133
+ method: "GET",
134
+ path: (data) => `/users/${data.variables.userId}`,
135
+ variablesSchema: z.object({ userId: z.string() }),
136
+ outputSchema: z.object({
137
+ id: z.string(),
138
+ name: z.string(),
139
+ email: z.string(),
140
+ }),
141
+ });
142
+
143
+ // Direct call — pass { variables: { userId: "123" } }
144
+ const { data } = await getUserById({ variables: { userId: "123" } });
145
+
146
+ // React Query — must pass data so queryKey and queryFn get userId
147
+ const { data } = useQuery(
148
+ getUserById.queryOptions({
149
+ data: { variables: { userId: "123" } },
150
+ staleTime: 60_000,
151
+ }),
152
+ );
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Example: POST with request body (input)
158
+
159
+ Use `inputSchema` for the body and optionally `axiosOptions` to pass it to Axios:
160
+
161
+ ```ts
162
+ const createUser = client.create({
163
+ method: "POST",
164
+ path: "/users",
165
+ inputSchema: z.object({
166
+ name: z.string().min(1),
167
+ email: z.string().email(),
168
+ }),
169
+ outputSchema: z.object({
170
+ id: z.string(),
171
+ name: z.string(),
172
+ email: z.string(),
173
+ }),
174
+ axiosOptions: (data) => ({
175
+ data: data.input,
176
+ }),
177
+ });
178
+
179
+ // Direct call
180
+ const { data } = await createUser({
181
+ input: { name: "Jane", email: "jane@example.com" },
182
+ });
183
+
184
+ // React Query mutation
185
+ const mutation = useMutation(
186
+ createUser.mutationOptions({
187
+ onSuccess: (user) => console.log("Created", user),
188
+ }),
189
+ );
190
+ mutation.mutate({ input: { name: "Jane", email: "jane@example.com" } });
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Example: Dynamic path and query params
196
+
197
+ Combine variables with a path function and `axiosOptions` for query params:
198
+
199
+ ```ts
200
+ const listUsers = client.create({
201
+ method: "GET",
202
+ path: "/users",
203
+ variablesSchema: z.object({
204
+ page: z.number().optional(),
205
+ limit: z.number().optional(),
206
+ }),
207
+ outputSchema: z.object({
208
+ users: z.array(z.object({ id: z.string(), name: z.string() })),
209
+ total: z.number(),
210
+ }),
211
+ axiosOptions: (data) => ({
212
+ params: data.variables,
213
+ }),
214
+ });
215
+
216
+ const { data } = await listUsers({
217
+ variables: { page: 1, limit: 10 },
218
+ });
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Example: PUT / PATCH / DELETE
224
+
225
+ Same pattern: use `inputSchema` for body and `axiosOptions` to pass it.
226
+
227
+ ```ts
228
+ const updateUser = client.create({
229
+ method: "PATCH",
230
+ path: (data) => `/users/${data.variables.userId}`,
231
+ variablesSchema: z.object({ userId: z.string() }),
232
+ inputSchema: z.object({
233
+ name: z.string().optional(),
234
+ email: z.string().email().optional(),
235
+ }),
236
+ outputSchema: z.object({
237
+ id: z.string(),
238
+ name: z.string(),
239
+ email: z.string(),
240
+ }),
241
+ axiosOptions: (data) => ({
242
+ data: data.input,
243
+ }),
244
+ });
245
+
246
+ await updateUser({
247
+ variables: { userId: "123" },
248
+ input: { name: "New Name" },
249
+ });
250
+ ```
251
+
252
+ ---
253
+
254
+ ## Using with React Query
255
+
256
+ ### Queries (GET)
257
+
258
+ - Use **`queryOptions({ data?, ...useQueryOptions })`**.
259
+ - If the endpoint has **input or variables**, pass **`data`** so both `queryKey` and `queryFn` receive it.
260
+ - You can pass any `useQuery` options (`staleTime`, `enabled`, etc.) and optional **`onSuccess`** / **`onError`** with the same payload shape.
261
+
262
+ ```ts
263
+ // No input/variables
264
+ useQuery(getProducts.queryOptions({ staleTime: 60_000 }));
265
+
266
+ // With variables (e.g. GET by id)
267
+ useQuery(
268
+ getUserById.queryOptions({
269
+ data: { variables: { userId: "123" } },
270
+ enabled: !!userId,
271
+ onSuccess: (user) => {},
272
+ onError: (err, { variables }) => {},
273
+ }),
274
+ );
275
+ ```
276
+
277
+ ### Mutations (POST / PUT / PATCH / DELETE)
278
+
279
+ - Use **`mutationOptions(options?)`** with `useMutation`.
280
+ - **`mutation.mutate(data)`** must match the endpoint’s `input`/`variables` shape.
281
+
282
+ ```ts
283
+ const mutation = useMutation(
284
+ createUser.mutationOptions({
285
+ onSuccess: (user) => {},
286
+ onError: (error, variables) => {},
287
+ }),
288
+ );
289
+
290
+ mutation.mutate({
291
+ input: { name: "Jane", email: "jane@example.com" },
292
+ });
293
+ ```
294
+
295
+ ---
296
+
297
+ ## Validation and errors
298
+
299
+ - **Input** and **variables** are validated with Zod before the request; invalid data throws **`ZodError`**.
300
+ - **Response** is parsed with `outputSchema` after the request; invalid response throws **`ZodError`**.
301
+ - Network or server errors are **AxiosError**.
302
+
303
+ So the callable and React Query helpers can throw **`ZodError | AxiosError`**. Handle both in `onError` or in try/catch:
304
+
305
+ ```ts
306
+ import { AxiosError } from "axios";
307
+ import { ZodError } from "zod";
308
+
309
+ const { data, error } = useQuery(
310
+ getUsers.queryOptions({
311
+ onError: (err) => {
312
+ if (err instanceof ZodError) {
313
+ console.error("Validation failed", err.flatten());
314
+ } else if (err instanceof AxiosError) {
315
+ console.error("Request failed", err.response?.status);
316
+ }
317
+ },
318
+ }),
319
+ );
13
320
  ```
14
321
 
15
- This project was created using `bun init` in bun v1.3.0. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
322
+ ---
323
+
324
+ ## Full example: small API module
325
+
326
+ ```ts
327
+ import axios from "axios";
328
+ import z from "zod";
329
+ import { createClient } from "@ryneex/api-client";
330
+
331
+ const axiosInstance = axios.create({
332
+ baseURL: "https://api.example.com",
333
+ headers: { "Content-Type": "application/json" },
334
+ });
335
+
336
+ const client = createClient(axiosInstance);
337
+
338
+ // Schemas
339
+ const userSchema = z.object({
340
+ id: z.string(),
341
+ name: z.string(),
342
+ email: z.string(),
343
+ });
344
+
345
+ // GET /users
346
+ export const getUsers = client.create({
347
+ method: "GET",
348
+ path: "/users",
349
+ outputSchema: z.object({ users: z.array(userSchema) }),
350
+ });
351
+
352
+ // GET /users/:id
353
+ export const getUser = client.create({
354
+ method: "GET",
355
+ path: (d) => `/users/${d.variables.id}`,
356
+ variablesSchema: z.object({ id: z.string() }),
357
+ outputSchema: userSchema,
358
+ });
359
+
360
+ // POST /users
361
+ export const createUser = client.create({
362
+ method: "POST",
363
+ path: "/users",
364
+ inputSchema: z.object({
365
+ name: z.string(),
366
+ email: z.string().email(),
367
+ }),
368
+ outputSchema: userSchema,
369
+ axiosOptions: (d) => ({ data: d.input }),
370
+ });
371
+
372
+ // Usage in a component
373
+ // const { data } = useQuery(getUsers.queryOptions());
374
+ // const { data } = useQuery(getUser.queryOptions({ data: { variables: { id: "1" } } }));
375
+ // const mutation = useMutation(createUser.mutationOptions());
376
+ // mutation.mutate({ input: { name: "Jane", email: "jane@example.com" } });
377
+ ```
package/index.d.ts CHANGED
@@ -1,35 +1,49 @@
1
- import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
2
- import { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
1
+ import * as axios from 'axios';
2
+ import { AxiosRequestConfig, AxiosError, AxiosInstance } from 'axios';
3
3
  import z, { ZodError } from 'zod';
4
+ import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
5
+
6
+ type ClientPayload<TInput, TVariables> = {} & (unknown extends TInput ? unknown : {
7
+ input: TInput;
8
+ }) & (unknown extends TVariables ? unknown : {
9
+ variables: TVariables;
10
+ });
11
+ type OptionalPayload<T> = object extends T ? void : T;
12
+ type ClientOptions<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.infer<TOutputSchema>, TInput = z.infer<TInputSchema>, TVariables = z.infer<TVariablesSchema>> = {
13
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
14
+ path: string | ((payload: ClientPayload<TInput, TVariables>) => string);
15
+ axiosOptions?: (payload: ClientPayload<TInput, TVariables>) => AxiosRequestConfig;
16
+ variablesSchema?: TVariablesSchema;
17
+ inputSchema?: TInputSchema;
18
+ outputSchema: TOutputSchema;
19
+ transform?: (data: z.infer<TOutputSchema>, payload: ClientPayload<TInput, TVariables>) => TOutput;
20
+ };
4
21
 
5
- type ReactQueryOptions<TResponse, TData = void> = Omit<UseQueryOptions<TResponse, ZodError<TResponse> | AxiosError>, "queryFn" | "queryKey"> & {
22
+ type ReactQueryOptions<TOutput, TInput, TVariables> = Omit<UseQueryOptions<TOutput, ZodError<TOutput> | AxiosError>, "queryFn" | "queryKey"> & {
6
23
  queryKey?: unknown[];
7
- } & (TData extends void ? {
8
- data?: void;
9
- } : {
10
- data: TData;
24
+ } & (object extends ClientPayload<TInput, TVariables> ? unknown : {
25
+ data: ClientPayload<TInput, TVariables>;
11
26
  }) & {
12
- onSuccess?: (data: TResponse, variables: TData) => void;
13
- onError?: (error: ZodError<TResponse> | AxiosError, variables: TData) => void;
27
+ onSuccess?: (data: TOutput, payload: ClientPayload<TInput, TVariables>) => void;
28
+ onError?: (error: ZodError<TOutput> | AxiosError, payload: ClientPayload<TInput, TVariables>) => void;
14
29
  };
15
- type ReactMutationOptions<TResponse, TData = void> = Omit<UseMutationOptions<TResponse, ZodError<TResponse> | AxiosError, TData>, "mutationFn" | "mutationKey"> & {
16
- mutationKey?: unknown[];
17
- };
18
- declare class BaseApiClient {
19
- readonly axios: AxiosInstance;
20
- constructor(axios: AxiosInstance);
21
- createEndpoint<TResponse, TData = void>({ method, path, axiosOptions: axiosOptionsFn, dataSchema, responseSchema, }: {
22
- method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
23
- path: string | ((data: TData) => string);
24
- axiosOptions?: (data: TData) => AxiosRequestConfig;
25
- dataSchema?: z.ZodType<TData>;
26
- responseSchema: z.ZodType<TResponse>;
27
- }): ((data: TData) => Promise<AxiosResponse<TResponse>>) & {
28
- queryKey: (data: TData | void) => (string | NonNullable<TData>)[];
29
- queryOptions: (opts: TData extends void ? ReactQueryOptions<TResponse> | void : ReactQueryOptions<TResponse, TData>) => UseQueryOptions<TResponse, ZodError<TResponse> | AxiosError>;
30
- mutationKey: () => string[];
31
- mutationOptions: (opts: ReactMutationOptions<TResponse, TData> | void) => UseMutationOptions<TResponse, ZodError<TResponse> | AxiosError, TData>;
30
+ type ReactMutationOptions<TOutput, TInput, TVariables> = Omit<UseMutationOptions<TOutput, ZodError<TOutput> | AxiosError, object extends ClientPayload<TInput, TVariables> ? void : ClientPayload<TInput, TVariables>>, "mutationFn"> & {};
31
+
32
+ declare function createClient(axios: AxiosInstance): {
33
+ create: <TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.core.output<TOutputSchema>, TInput = z.core.output<TInputSchema>, TVariables = z.core.output<TVariablesSchema>>(opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables>) => ((_payload: OptionalPayload<ClientPayload<TInput, TVariables>>) => Promise<axios.AxiosResponse<TOutput, any, {}>>) & {
34
+ queryOptions: (_opts: object extends ClientPayload<TInput, TVariables> ? ReactQueryOptions<TOutput, TInput, TVariables> | void : ReactQueryOptions<TOutput, TInput, TVariables>) => UseQueryOptions<TOutput, ZodError<TOutput> | AxiosError>;
35
+ mutationOptions: (_opts: ReactMutationOptions<TOutput, TInput, TVariables> | void) => UseMutationOptions<TOutput, ZodError<TOutput> | AxiosError, object extends ClientPayload<TInput, TVariables> ? void : ClientPayload<TInput, TVariables>>;
36
+ config: {
37
+ inputSchema: undefined extends TInputSchema ? undefined : NonNullable<TInputSchema>;
38
+ variablesSchema: undefined extends TVariablesSchema ? undefined : NonNullable<TVariablesSchema>;
39
+ axios: AxiosInstance;
40
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
41
+ path: string | ((payload: ClientPayload<TInput, TVariables>) => string);
42
+ axiosOptions?: ((payload: ClientPayload<TInput, TVariables>) => axios.AxiosRequestConfig) | undefined;
43
+ outputSchema: TOutputSchema;
44
+ transform?: ((data: z.core.output<TOutputSchema>, payload: ClientPayload<TInput, TVariables>) => TOutput) | undefined;
45
+ };
32
46
  };
33
- }
47
+ };
34
48
 
35
- export { BaseApiClient };
49
+ export { createClient };
package/index.js CHANGED
@@ -1,79 +1,84 @@
1
- // src/lib/base-api-client.ts
2
- import "@tanstack/react-query";
1
+ // src/lib/api-client.ts
2
+ import "zod";
3
+
4
+ // src/lib/call-api.ts
3
5
  import "zod";
4
- var BaseApiClient = class {
5
- axios;
6
- constructor(axios) {
7
- this.axios = axios;
6
+ async function callApi(opts, data) {
7
+ if (typeof data !== "object")
8
+ throw new Error("API SDK: Data must be an object");
9
+ if (opts.inputSchema && "input" in data) {
10
+ opts.inputSchema.parse(data.input);
11
+ }
12
+ if (opts.variablesSchema && "variables" in data) {
13
+ opts.variablesSchema.parse(data.variables);
14
+ }
15
+ const axiosOptions = opts.axiosOptions?.(data);
16
+ const url = typeof opts.path === "function" ? opts.path(data) : opts.path;
17
+ if (opts.method === "GET") {
18
+ const response = await opts.axios.get(url, axiosOptions);
19
+ return getResponse(opts, data, response);
20
+ }
21
+ if (opts.method === "POST") {
22
+ const response = await opts.axios.post(
23
+ url,
24
+ axiosOptions?.data,
25
+ axiosOptions
26
+ );
27
+ return getResponse(opts, data, response);
28
+ }
29
+ if (opts.method === "PUT") {
30
+ const response = await opts.axios.put(
31
+ url,
32
+ axiosOptions?.data,
33
+ axiosOptions
34
+ );
35
+ return getResponse(opts, data, response);
36
+ }
37
+ if (opts.method === "PATCH") {
38
+ const response = await opts.axios.patch(
39
+ url,
40
+ axiosOptions?.data,
41
+ axiosOptions
42
+ );
43
+ return getResponse(opts, data, response);
44
+ }
45
+ if (opts.method === "DELETE") {
46
+ const response = await opts.axios.delete(url, axiosOptions);
47
+ return getResponse(opts, data, response);
48
+ }
49
+ throw new Error(`API SDK: Unsupported method: ${opts.method}`);
50
+ }
51
+ function getResponse(opts, payload, response) {
52
+ const parsedData = opts.outputSchema.parse(response.data);
53
+ if (opts.transform) {
54
+ return { ...response, data: opts.transform(parsedData, payload) };
8
55
  }
9
- createEndpoint({
10
- method,
11
- path,
12
- axiosOptions: axiosOptionsFn,
13
- dataSchema,
14
- responseSchema
15
- }) {
56
+ return { ...response, data: parsedData };
57
+ }
58
+
59
+ // src/lib/api-client.ts
60
+ import "@tanstack/react-query";
61
+ function createClient(axios) {
62
+ function create(opts) {
16
63
  const uuid = crypto.randomUUID();
17
- const call = async (data) => {
18
- if (dataSchema) {
19
- dataSchema.parse(data);
20
- }
21
- const axiosOptions = axiosOptionsFn?.(data);
22
- const url = typeof path === "function" ? path(data) : path;
23
- if (method === "GET") {
24
- const response = await this.axios.get(url, axiosOptions);
25
- responseSchema.parse(response.data);
26
- return response;
27
- }
28
- if (method === "POST") {
29
- const response = await this.axios.post(
30
- url,
31
- axiosOptions?.data,
32
- axiosOptions
33
- );
34
- responseSchema.parse(response.data);
35
- return response;
36
- }
37
- if (method === "PUT") {
38
- const response = await this.axios.put(
39
- url,
40
- axiosOptions?.data,
41
- axiosOptions
42
- );
43
- responseSchema.parse(response.data);
44
- return response;
45
- }
46
- if (method === "PATCH") {
47
- const response = await this.axios.patch(
48
- url,
49
- axiosOptions?.data,
50
- axiosOptions
51
- );
52
- responseSchema.parse(response.data);
53
- return response;
54
- }
55
- if (method === "DELETE") {
56
- const response = await this.axios.delete(url, axiosOptions);
57
- responseSchema.parse(response.data);
58
- return response;
59
- }
60
- throw new Error(`API SDK: Unsupported method: ${method}`);
64
+ const apiOptionas = { ...opts, axios };
65
+ const call = async (_payload) => {
66
+ const payload = _payload ?? {};
67
+ return callApi(apiOptionas, payload);
61
68
  };
62
69
  const queryKey = (data) => data ? ["api-call", "query", uuid, data] : ["api-call", "query", uuid];
63
70
  const mutationKey = () => ["api-call", "mutation", uuid];
64
- const queryOptions = (opts) => {
65
- const { data, ...options } = opts ?? {};
71
+ const queryOptions = (_opts) => {
72
+ const { data: _data, ...options } = _opts ?? {};
73
+ const data = _data ?? {};
66
74
  return {
67
75
  queryFn: async () => {
68
76
  try {
69
- const response = await call(data);
77
+ const response = await callApi(apiOptionas, data);
70
78
  options.onSuccess?.(response.data, data);
71
79
  return response.data;
72
80
  } catch (error) {
73
- options.onError?.(
74
- error,
75
- data
76
- );
81
+ options.onError?.(error, data);
77
82
  throw error;
78
83
  }
79
84
  },
@@ -81,11 +86,12 @@ var BaseApiClient = class {
81
86
  ...options
82
87
  };
83
88
  };
84
- const mutationOptions = (opts) => {
85
- const options = opts ?? {};
89
+ const mutationOptions = (_opts) => {
90
+ const options = _opts ?? {};
86
91
  return {
87
- mutationFn: async (data) => {
88
- const response = await call(data);
92
+ mutationFn: async (_data) => {
93
+ const data = _data ?? {};
94
+ const response = await callApi(apiOptionas, data);
89
95
  return response.data;
90
96
  },
91
97
  mutationKey: mutationKey(),
@@ -93,13 +99,17 @@ var BaseApiClient = class {
93
99
  };
94
100
  };
95
101
  return Object.assign(call, {
96
- queryKey,
97
102
  queryOptions,
98
- mutationKey,
99
- mutationOptions
103
+ mutationOptions,
104
+ config: {
105
+ ...apiOptionas,
106
+ inputSchema: opts.inputSchema,
107
+ variablesSchema: opts.variablesSchema
108
+ }
100
109
  });
101
110
  }
102
- };
111
+ return { create };
112
+ }
103
113
  export {
104
- BaseApiClient
114
+ createClient
105
115
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ryneex/api-client",
3
3
  "module": "src/index.ts",
4
4
  "type": "module",
5
- "version": "0.0.51",
5
+ "version": "1.0.0-beta.0",
6
6
  "exports": {
7
7
  ".": "./index.js"
8
8
  },