@htkimura/files-storage-backend.rest-client 0.0.9

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/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@htkimura/files-storage-backend.rest-client",
3
+ "version": "0.0.9",
4
+ "description": "REST client of files-storage-backend",
5
+ "author": "Henry Kimura",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "publish": "npm publish --access public"
9
+ },
10
+ "main": "src/generated/index.ts",
11
+ "files": [
12
+ "src/generated"
13
+ ],
14
+ "exports": {
15
+ ".": "./src/generated/index.ts"
16
+ },
17
+ "dependencies": {
18
+ "@tanstack/react-query": "^5.66.0",
19
+ "axios": "^1.7.9",
20
+ "react": "^19.0.0",
21
+ "react-dom": "^19.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^22.13.5",
25
+ "@types/react": "^19.0.10",
26
+ "@types/react-dom": "^19.0.4",
27
+ "typescript": "^5.7.3"
28
+ }
29
+ }
@@ -0,0 +1,3 @@
1
+ export * from './model';
2
+ export * from './storage/storage';
3
+ export * from './user/user';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+
9
+ export interface CreateUserDto {
10
+ email: string;
11
+ password: string;
12
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+
9
+ export * from './createUserDto';
10
+ export * from './loginDto';
11
+ export * from './refreshTokenDto';
12
+ export * from './user';
13
+ export * from './userLogin';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+
9
+ export interface LoginDto {
10
+ email: string;
11
+ password: string;
12
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+
9
+ export interface RefreshTokenDto {
10
+ refreshToken: string;
11
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+
9
+ export interface User {
10
+ id: string;
11
+ _id: string;
12
+ email: string;
13
+ refreshToken: string;
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ import type { User } from './user';
9
+
10
+ export interface UserLogin {
11
+ token: string;
12
+ refreshToken: string;
13
+ user: User;
14
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ import {
9
+ useMutation,
10
+ useQuery
11
+ } from '@tanstack/react-query'
12
+ import type {
13
+ MutationFunction,
14
+ QueryFunction,
15
+ QueryKey,
16
+ UseMutationOptions,
17
+ UseMutationResult,
18
+ UseQueryOptions,
19
+ UseQueryResult
20
+ } from '@tanstack/react-query'
21
+ import axios from 'axios'
22
+ import type {
23
+ AxiosError,
24
+ AxiosRequestConfig,
25
+ AxiosResponse
26
+ } from 'axios'
27
+
28
+
29
+
30
+ export const storageControllerGetObjectUrl = (
31
+ objectName: string, options?: AxiosRequestConfig
32
+ ): Promise<AxiosResponse<void>> => {
33
+
34
+
35
+ return axios.get(
36
+ `/objects/${objectName}`,options
37
+ );
38
+ }
39
+
40
+
41
+ export const getStorageControllerGetObjectUrlQueryKey = (objectName: string,) => {
42
+ return [`/objects/${objectName}`] as const;
43
+ }
44
+
45
+
46
+ export const getStorageControllerGetObjectUrlQueryOptions = <TData = Awaited<ReturnType<typeof storageControllerGetObjectUrl>>, TError = AxiosError<unknown>>(objectName: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof storageControllerGetObjectUrl>>, TError, TData>, axios?: AxiosRequestConfig}
47
+ ) => {
48
+
49
+ const {query: queryOptions, axios: axiosOptions} = options ?? {};
50
+
51
+ const queryKey = queryOptions?.queryKey ?? getStorageControllerGetObjectUrlQueryKey(objectName);
52
+
53
+
54
+
55
+ const queryFn: QueryFunction<Awaited<ReturnType<typeof storageControllerGetObjectUrl>>> = ({ signal }) => storageControllerGetObjectUrl(objectName, { signal, ...axiosOptions });
56
+
57
+
58
+
59
+
60
+
61
+ return { queryKey, queryFn, enabled: !!(objectName), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof storageControllerGetObjectUrl>>, TError, TData> & { queryKey: QueryKey }
62
+ }
63
+
64
+ export type StorageControllerGetObjectUrlQueryResult = NonNullable<Awaited<ReturnType<typeof storageControllerGetObjectUrl>>>
65
+ export type StorageControllerGetObjectUrlQueryError = AxiosError<unknown>
66
+
67
+
68
+
69
+ export function useStorageControllerGetObjectUrl<TData = Awaited<ReturnType<typeof storageControllerGetObjectUrl>>, TError = AxiosError<unknown>>(
70
+ objectName: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof storageControllerGetObjectUrl>>, TError, TData>, axios?: AxiosRequestConfig}
71
+
72
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
73
+
74
+ const queryOptions = getStorageControllerGetObjectUrlQueryOptions(objectName,options)
75
+
76
+ const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
77
+
78
+ query.queryKey = queryOptions.queryKey ;
79
+
80
+ return query;
81
+ }
82
+
83
+
84
+
85
+ export const storageControllerUploadObject = (
86
+ options?: AxiosRequestConfig
87
+ ): Promise<AxiosResponse<void>> => {
88
+
89
+
90
+ return axios.post(
91
+ `/objects`,undefined,options
92
+ );
93
+ }
94
+
95
+
96
+
97
+ export const getStorageControllerUploadObjectMutationOptions = <TData = Awaited<ReturnType<typeof storageControllerUploadObject>>, TError = AxiosError<unknown>,
98
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,void, TContext>, axios?: AxiosRequestConfig}
99
+ ) => {
100
+ const mutationKey = ['storageControllerUploadObject'];
101
+ const {mutation: mutationOptions, axios: axiosOptions} = options ?
102
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
103
+ options
104
+ : {...options, mutation: {...options.mutation, mutationKey}}
105
+ : {mutation: { mutationKey, }, axios: undefined};
106
+
107
+
108
+
109
+
110
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof storageControllerUploadObject>>, void> = () => {
111
+
112
+
113
+ return storageControllerUploadObject(axiosOptions)
114
+ }
115
+
116
+
117
+
118
+
119
+ return { mutationFn, ...mutationOptions } as UseMutationOptions<TData, TError,void, TContext>}
120
+
121
+ export type StorageControllerUploadObjectMutationResult = NonNullable<Awaited<ReturnType<typeof storageControllerUploadObject>>>
122
+
123
+ export type StorageControllerUploadObjectMutationError = AxiosError<unknown>
124
+
125
+ export const useStorageControllerUploadObject = <TData = Awaited<ReturnType<typeof storageControllerUploadObject>>, TError = AxiosError<unknown>,
126
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,void, TContext>, axios?: AxiosRequestConfig}
127
+ ): UseMutationResult<
128
+ TData,
129
+ TError,
130
+ void,
131
+ TContext
132
+ > => {
133
+
134
+ const mutationOptions = getStorageControllerUploadObjectMutationOptions(options);
135
+
136
+ return useMutation(mutationOptions);
137
+ }
138
+
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ import {
9
+ useMutation,
10
+ useQuery
11
+ } from '@tanstack/react-query'
12
+ import type {
13
+ MutationFunction,
14
+ QueryFunction,
15
+ QueryKey,
16
+ UseMutationOptions,
17
+ UseMutationResult,
18
+ UseQueryOptions,
19
+ UseQueryResult
20
+ } from '@tanstack/react-query'
21
+ import axios from 'axios'
22
+ import type {
23
+ AxiosError,
24
+ AxiosRequestConfig,
25
+ AxiosResponse
26
+ } from 'axios'
27
+ import type {
28
+ CreateUserDto,
29
+ LoginDto,
30
+ RefreshTokenDto,
31
+ User,
32
+ UserLogin
33
+ } from '.././model'
34
+
35
+
36
+
37
+ /**
38
+ * Creates a new user and returns the created user. We don't have plans for now to implement this on frontend, but it's here for testing purposes
39
+ * @summary Sign up route where a user is created
40
+ */
41
+ export const createUser = (
42
+ createUserDto: CreateUserDto, options?: AxiosRequestConfig
43
+ ): Promise<AxiosResponse<void>> => {
44
+
45
+
46
+ return axios.post(
47
+ `/users`,
48
+ createUserDto,options
49
+ );
50
+ }
51
+
52
+
53
+
54
+ export const getCreateUserMutationOptions = <TData = Awaited<ReturnType<typeof createUser>>, TError = AxiosError<unknown>,
55
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: CreateUserDto}, TContext>, axios?: AxiosRequestConfig}
56
+ ) => {
57
+ const mutationKey = ['createUser'];
58
+ const {mutation: mutationOptions, axios: axiosOptions} = options ?
59
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
60
+ options
61
+ : {...options, mutation: {...options.mutation, mutationKey}}
62
+ : {mutation: { mutationKey, }, axios: undefined};
63
+
64
+
65
+
66
+
67
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUser>>, {data: CreateUserDto}> = (props) => {
68
+ const {data} = props ?? {};
69
+
70
+ return createUser(data,axiosOptions)
71
+ }
72
+
73
+
74
+
75
+
76
+ return { mutationFn, ...mutationOptions } as UseMutationOptions<TData, TError,{data: CreateUserDto}, TContext>}
77
+
78
+ export type CreateUserMutationResult = NonNullable<Awaited<ReturnType<typeof createUser>>>
79
+ export type CreateUserMutationBody = CreateUserDto
80
+ export type CreateUserMutationError = AxiosError<unknown>
81
+
82
+ /**
83
+ * @summary Sign up route where a user is created
84
+ */
85
+ export const useCreateUser = <TData = Awaited<ReturnType<typeof createUser>>, TError = AxiosError<unknown>,
86
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: CreateUserDto}, TContext>, axios?: AxiosRequestConfig}
87
+ ): UseMutationResult<
88
+ TData,
89
+ TError,
90
+ {data: CreateUserDto},
91
+ TContext
92
+ > => {
93
+
94
+ const mutationOptions = getCreateUserMutationOptions(options);
95
+
96
+ return useMutation(mutationOptions);
97
+ }
98
+ /**
99
+ * Receives user auth data, check the authentication and returns LoginData
100
+ * @summary Sign in route for authentication
101
+ */
102
+ export const login = (
103
+ loginDto: LoginDto, options?: AxiosRequestConfig
104
+ ): Promise<AxiosResponse<UserLogin>> => {
105
+
106
+
107
+ return axios.post(
108
+ `/users/login`,
109
+ loginDto,options
110
+ );
111
+ }
112
+
113
+
114
+
115
+ export const getLoginMutationOptions = <TData = Awaited<ReturnType<typeof login>>, TError = AxiosError<unknown>,
116
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: LoginDto}, TContext>, axios?: AxiosRequestConfig}
117
+ ) => {
118
+ const mutationKey = ['login'];
119
+ const {mutation: mutationOptions, axios: axiosOptions} = options ?
120
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
121
+ options
122
+ : {...options, mutation: {...options.mutation, mutationKey}}
123
+ : {mutation: { mutationKey, }, axios: undefined};
124
+
125
+
126
+
127
+
128
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof login>>, {data: LoginDto}> = (props) => {
129
+ const {data} = props ?? {};
130
+
131
+ return login(data,axiosOptions)
132
+ }
133
+
134
+
135
+
136
+
137
+ return { mutationFn, ...mutationOptions } as UseMutationOptions<TData, TError,{data: LoginDto}, TContext>}
138
+
139
+ export type LoginMutationResult = NonNullable<Awaited<ReturnType<typeof login>>>
140
+ export type LoginMutationBody = LoginDto
141
+ export type LoginMutationError = AxiosError<unknown>
142
+
143
+ /**
144
+ * @summary Sign in route for authentication
145
+ */
146
+ export const useLogin = <TData = Awaited<ReturnType<typeof login>>, TError = AxiosError<unknown>,
147
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: LoginDto}, TContext>, axios?: AxiosRequestConfig}
148
+ ): UseMutationResult<
149
+ TData,
150
+ TError,
151
+ {data: LoginDto},
152
+ TContext
153
+ > => {
154
+
155
+ const mutationOptions = getLoginMutationOptions(options);
156
+
157
+ return useMutation(mutationOptions);
158
+ }
159
+ /**
160
+ * Receives the user refresh token, validates it and return an updated token
161
+ * @summary Refreshes the user token
162
+ */
163
+ export const refreshToken = (
164
+ refreshTokenDto: RefreshTokenDto, options?: AxiosRequestConfig
165
+ ): Promise<AxiosResponse<UserLogin>> => {
166
+
167
+
168
+ return axios.post(
169
+ `/users/refresh-token`,
170
+ refreshTokenDto,options
171
+ );
172
+ }
173
+
174
+
175
+
176
+ export const getRefreshTokenMutationOptions = <TData = Awaited<ReturnType<typeof refreshToken>>, TError = AxiosError<unknown>,
177
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: RefreshTokenDto}, TContext>, axios?: AxiosRequestConfig}
178
+ ) => {
179
+ const mutationKey = ['refreshToken'];
180
+ const {mutation: mutationOptions, axios: axiosOptions} = options ?
181
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
182
+ options
183
+ : {...options, mutation: {...options.mutation, mutationKey}}
184
+ : {mutation: { mutationKey, }, axios: undefined};
185
+
186
+
187
+
188
+
189
+ const mutationFn: MutationFunction<Awaited<ReturnType<typeof refreshToken>>, {data: RefreshTokenDto}> = (props) => {
190
+ const {data} = props ?? {};
191
+
192
+ return refreshToken(data,axiosOptions)
193
+ }
194
+
195
+
196
+
197
+
198
+ return { mutationFn, ...mutationOptions } as UseMutationOptions<TData, TError,{data: RefreshTokenDto}, TContext>}
199
+
200
+ export type RefreshTokenMutationResult = NonNullable<Awaited<ReturnType<typeof refreshToken>>>
201
+ export type RefreshTokenMutationBody = RefreshTokenDto
202
+ export type RefreshTokenMutationError = AxiosError<unknown>
203
+
204
+ /**
205
+ * @summary Refreshes the user token
206
+ */
207
+ export const useRefreshToken = <TData = Awaited<ReturnType<typeof refreshToken>>, TError = AxiosError<unknown>,
208
+ TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: RefreshTokenDto}, TContext>, axios?: AxiosRequestConfig}
209
+ ): UseMutationResult<
210
+ TData,
211
+ TError,
212
+ {data: RefreshTokenDto},
213
+ TContext
214
+ > => {
215
+
216
+ const mutationOptions = getRefreshTokenMutationOptions(options);
217
+
218
+ return useMutation(mutationOptions);
219
+ }
220
+ /**
221
+ * Returns the authenticated user data using the token as reference
222
+ * @summary Get the authenticated user data
223
+ */
224
+ export const me = (
225
+ options?: AxiosRequestConfig
226
+ ): Promise<AxiosResponse<User>> => {
227
+
228
+
229
+ return axios.get(
230
+ `/users/me`,options
231
+ );
232
+ }
233
+
234
+
235
+ export const getMeQueryKey = () => {
236
+ return [`/users/me`] as const;
237
+ }
238
+
239
+
240
+ export const getMeQueryOptions = <TData = Awaited<ReturnType<typeof me>>, TError = AxiosError<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof me>>, TError, TData>, axios?: AxiosRequestConfig}
241
+ ) => {
242
+
243
+ const {query: queryOptions, axios: axiosOptions} = options ?? {};
244
+
245
+ const queryKey = queryOptions?.queryKey ?? getMeQueryKey();
246
+
247
+
248
+
249
+ const queryFn: QueryFunction<Awaited<ReturnType<typeof me>>> = ({ signal }) => me({ signal, ...axiosOptions });
250
+
251
+
252
+
253
+
254
+
255
+ return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof me>>, TError, TData> & { queryKey: QueryKey }
256
+ }
257
+
258
+ export type MeQueryResult = NonNullable<Awaited<ReturnType<typeof me>>>
259
+ export type MeQueryError = AxiosError<unknown>
260
+
261
+
262
+ /**
263
+ * @summary Get the authenticated user data
264
+ */
265
+
266
+ export function useMe<TData = Awaited<ReturnType<typeof me>>, TError = AxiosError<unknown>>(
267
+ options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof me>>, TError, TData>, axios?: AxiosRequestConfig}
268
+
269
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
270
+
271
+ const queryOptions = getMeQueryOptions(options)
272
+
273
+ const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
274
+
275
+ query.queryKey = queryOptions.queryKey ;
276
+
277
+ return query;
278
+ }
279
+
280
+
281
+
282
+ /**
283
+ * Returns the authenticated user files URLs
284
+ * @summary Get the authenticated user files URLs
285
+ */
286
+ export const myFiles = (
287
+ options?: AxiosRequestConfig
288
+ ): Promise<AxiosResponse<string[]>> => {
289
+
290
+
291
+ return axios.get(
292
+ `/users/me/files`,options
293
+ );
294
+ }
295
+
296
+
297
+ export const getMyFilesQueryKey = () => {
298
+ return [`/users/me/files`] as const;
299
+ }
300
+
301
+
302
+ export const getMyFilesQueryOptions = <TData = Awaited<ReturnType<typeof myFiles>>, TError = AxiosError<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof myFiles>>, TError, TData>, axios?: AxiosRequestConfig}
303
+ ) => {
304
+
305
+ const {query: queryOptions, axios: axiosOptions} = options ?? {};
306
+
307
+ const queryKey = queryOptions?.queryKey ?? getMyFilesQueryKey();
308
+
309
+
310
+
311
+ const queryFn: QueryFunction<Awaited<ReturnType<typeof myFiles>>> = ({ signal }) => myFiles({ signal, ...axiosOptions });
312
+
313
+
314
+
315
+
316
+
317
+ return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof myFiles>>, TError, TData> & { queryKey: QueryKey }
318
+ }
319
+
320
+ export type MyFilesQueryResult = NonNullable<Awaited<ReturnType<typeof myFiles>>>
321
+ export type MyFilesQueryError = AxiosError<unknown>
322
+
323
+
324
+ /**
325
+ * @summary Get the authenticated user files URLs
326
+ */
327
+
328
+ export function useMyFiles<TData = Awaited<ReturnType<typeof myFiles>>, TError = AxiosError<unknown>>(
329
+ options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof myFiles>>, TError, TData>, axios?: AxiosRequestConfig}
330
+
331
+ ): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
332
+
333
+ const queryOptions = getMyFilesQueryOptions(options)
334
+
335
+ const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
336
+
337
+ query.queryKey = queryOptions.queryKey ;
338
+
339
+ return query;
340
+ }
341
+
342
+
343
+