generator-kodly-react-app 1.0.7 → 1.0.11
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/generators/app/index.js +63 -18
- package/generators/app/templates/.env.dev +4 -0
- package/generators/app/templates/.env.sandbox +4 -0
- package/generators/app/templates/STRUCTURE.md +661 -0
- package/generators/app/templates/components.json +22 -0
- package/generators/app/templates/gitignore.template +78 -2
- package/generators/app/templates/index.html +14 -6
- package/generators/app/templates/openapi-ts.config.ts +29 -0
- package/generators/app/templates/package.json +40 -26
- package/generators/app/templates/public/favicon.svg +4 -0
- package/generators/app/templates/src/app.tsx +8 -8
- package/generators/app/templates/src/components/layout/language-switcher.tsx +40 -0
- package/generators/app/templates/src/components/layout/theme-switcher.tsx +37 -0
- package/generators/app/templates/src/components/theme/theme-provider.tsx +22 -28
- package/generators/app/templates/src/components/ui/button.tsx +34 -32
- package/generators/app/templates/src/components/ui/card.tsx +76 -0
- package/generators/app/templates/src/components/ui/field.tsx +242 -0
- package/generators/app/templates/src/components/ui/form.tsx +129 -0
- package/generators/app/templates/src/components/ui/input-group.tsx +170 -0
- package/generators/app/templates/src/components/ui/input.tsx +19 -21
- package/generators/app/templates/src/components/ui/label.tsx +24 -0
- package/generators/app/templates/src/components/ui/select.tsx +184 -0
- package/generators/app/templates/src/components/ui/separator.tsx +31 -0
- package/generators/app/templates/src/components/ui/textarea.tsx +22 -0
- package/generators/app/templates/src/index.css +83 -26
- package/generators/app/templates/src/lib/i18n.ts +31 -16
- package/generators/app/templates/src/lib/routes.ts +14 -0
- package/generators/app/templates/src/lib/utils.ts +3 -4
- package/generators/app/templates/src/locales/en/common.json +5 -0
- package/generators/app/templates/src/locales/en/theme.json +5 -0
- package/generators/app/templates/src/locales/index.ts +31 -0
- package/generators/app/templates/src/locales/ja/common.json +5 -0
- package/generators/app/templates/src/locales/ja/theme.json +6 -0
- package/generators/app/templates/src/main.tsx +19 -15
- package/generators/app/templates/src/modules/app/layouts/app-layout.tsx +37 -0
- package/generators/app/templates/src/modules/app/locales/app-en.json +9 -0
- package/generators/app/templates/src/modules/app/locales/app-ja.json +9 -0
- package/generators/app/templates/src/modules/auth/components/forgot-password-form.tsx +74 -0
- package/generators/app/templates/src/modules/auth/components/login-form.tsx +95 -0
- package/generators/app/templates/src/modules/auth/components/reset-password-form.tsx +112 -0
- package/generators/app/templates/src/modules/auth/components/signup-form.tsx +92 -0
- package/generators/app/templates/src/modules/auth/{auth-context.tsx → contexts/auth-context.tsx} +3 -3
- package/generators/app/templates/src/modules/auth/hooks/use-auth-hook.ts +180 -0
- package/generators/app/templates/src/modules/auth/layouts/auth-layout.tsx +28 -0
- package/generators/app/templates/src/modules/auth/locales/auth-en.json +105 -0
- package/generators/app/templates/src/modules/auth/locales/auth-ja.json +105 -0
- package/generators/app/templates/src/modules/auth/schemas/form-schemas.ts +26 -0
- package/generators/app/templates/src/modules/landing/components/auth-hero.tsx +34 -0
- package/generators/app/templates/src/modules/landing/components/welcome-hero.tsx +24 -0
- package/generators/app/templates/src/modules/landing/landing-page-layout.tsx +24 -0
- package/generators/app/templates/src/modules/landing/landing-page.tsx +17 -0
- package/generators/app/templates/src/modules/landing/layouts/landing-page-layout.tsx +24 -0
- package/generators/app/templates/src/modules/landing/locales/landing-en.json +12 -0
- package/generators/app/templates/src/modules/landing/locales/landing-ja.json +11 -0
- package/generators/app/templates/src/openapi-client-config.ts +6 -0
- package/generators/app/templates/src/routeTree.gen.ts +268 -3
- package/generators/app/templates/src/router.tsx +2 -2
- package/generators/app/templates/src/routes/__root.tsx +2 -2
- package/generators/app/templates/src/routes/_landing/index.tsx +10 -0
- package/generators/app/templates/src/routes/_landing/route.tsx +14 -0
- package/generators/app/templates/src/routes/app/index.tsx +4 -21
- package/generators/app/templates/src/routes/app/route.tsx +12 -8
- package/generators/app/templates/src/routes/auth/forgot-password.tsx +10 -0
- package/generators/app/templates/src/routes/auth/login.tsx +6 -7
- package/generators/app/templates/src/routes/auth/reset-password.tsx +15 -0
- package/generators/app/templates/src/routes/auth/route.tsx +23 -6
- package/generators/app/templates/src/routes/auth/signup.tsx +11 -0
- package/generators/app/templates/src/sdk/@tanstack/react-query.gen.ts +91 -0
- package/generators/app/templates/src/sdk/client/client.gen.ts +167 -0
- package/generators/app/templates/src/sdk/client/index.ts +23 -0
- package/generators/app/templates/src/sdk/client/types.gen.ts +197 -0
- package/generators/app/templates/src/sdk/client/utils.gen.ts +213 -0
- package/generators/app/templates/src/sdk/client.gen.ts +18 -0
- package/generators/app/templates/src/sdk/core/auth.gen.ts +42 -0
- package/generators/app/templates/src/sdk/core/bodySerializer.gen.ts +100 -0
- package/generators/app/templates/src/sdk/core/params.gen.ts +176 -0
- package/generators/app/templates/src/sdk/core/pathSerializer.gen.ts +181 -0
- package/generators/app/templates/src/sdk/core/queryKeySerializer.gen.ts +136 -0
- package/generators/app/templates/src/sdk/core/serverSentEvents.gen.ts +266 -0
- package/generators/app/templates/src/sdk/core/types.gen.ts +118 -0
- package/generators/app/templates/src/sdk/core/utils.gen.ts +143 -0
- package/generators/app/templates/src/sdk/index.ts +4 -0
- package/generators/app/templates/src/sdk/schemas.gen.ts +195 -0
- package/generators/app/templates/src/sdk/sdk.gen.ts +80 -0
- package/generators/app/templates/src/sdk/types.gen.ts +158 -0
- package/generators/app/templates/src/sdk/zod.gen.ts +148 -0
- package/generators/app/templates/src/vite-env.d.ts +2 -1
- package/generators/app/templates/tsconfig.json +1 -1
- package/generators/app/templates/vite.config.js +35 -21
- package/generators/constants.js +1 -1
- package/package.json +3 -2
- package/generators/app/templates/.env.example +0 -5
- package/generators/app/templates/README.md +0 -62
- package/generators/app/templates/src/lib/api/client.ts +0 -35
- package/generators/app/templates/src/locales/en.json +0 -18
- package/generators/app/templates/src/modules/auth/auth-types.ts +0 -24
- package/generators/app/templates/src/modules/auth/login/login-form.tsx +0 -49
- package/generators/app/templates/src/modules/auth/login/login-page.tsx +0 -12
- package/generators/app/templates/src/modules/auth/use-auth-hook.ts +0 -88
- package/generators/app/templates/src/routes/index.tsx +0 -12
- package/generators/app/templates/types.d.ts +0 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRouter } from '@tanstack/react-router';
|
|
2
|
-
import { routeTree } from '
|
|
2
|
+
import { routeTree } from '@/routeTree.gen';
|
|
3
3
|
|
|
4
4
|
export const router = createRouter({
|
|
5
|
-
basepath: import.meta.env.
|
|
5
|
+
basepath: import.meta.env.BASE_URL,
|
|
6
6
|
routeTree,
|
|
7
7
|
context: {
|
|
8
8
|
token: undefined!,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Outlet, createRootRouteWithContext } from '@tanstack/react-router';
|
|
2
|
-
import {
|
|
2
|
+
import type { AuthResponseDtoUserDetailDto } from '@/sdk';
|
|
3
3
|
|
|
4
4
|
interface RouterContext {
|
|
5
5
|
token: string;
|
|
6
|
-
data:
|
|
6
|
+
data: AuthResponseDtoUserDetailDto;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export const Route = createRootRouteWithContext<RouterContext>()({
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
2
|
+
import { LandingPage } from '@/modules/landing/landing-page';
|
|
3
|
+
|
|
4
|
+
export const Route = createFileRoute('/_landing/')({
|
|
5
|
+
component: RouteComponent,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
function RouteComponent() {
|
|
9
|
+
return <LandingPage />;
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LandingPageLayout } from '@/modules/landing/layouts/landing-page-layout';
|
|
2
|
+
import { createFileRoute, Outlet } from '@tanstack/react-router';
|
|
3
|
+
|
|
4
|
+
export const Route = createFileRoute('/_landing')({
|
|
5
|
+
component: RouteComponent,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
function RouteComponent() {
|
|
9
|
+
return (
|
|
10
|
+
<LandingPageLayout>
|
|
11
|
+
<Outlet />
|
|
12
|
+
</LandingPageLayout>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { createFileRoute } from '@tanstack/react-router';
|
|
2
|
-
import { Button } from '@/components/ui/button';
|
|
3
|
-
import { useLogout } from '@/modules/auth/use-auth-hook';
|
|
4
2
|
import { useTranslation } from 'react-i18next';
|
|
5
3
|
|
|
6
4
|
export const Route = createFileRoute('/app/')({
|
|
@@ -9,27 +7,12 @@ export const Route = createFileRoute('/app/')({
|
|
|
9
7
|
|
|
10
8
|
function AppIndex() {
|
|
11
9
|
const { t } = useTranslation();
|
|
12
|
-
const { mutate: logout, isPending } = useLogout();
|
|
13
|
-
|
|
14
|
-
const handleLogout = () => {
|
|
15
|
-
logout();
|
|
16
|
-
};
|
|
17
10
|
|
|
18
11
|
return (
|
|
19
|
-
<div className='
|
|
20
|
-
<div
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
<p className='text-muted-foreground'>{t('welcome.message')}</p>
|
|
24
|
-
</div>
|
|
25
|
-
<div>
|
|
26
|
-
<Button
|
|
27
|
-
onClick={handleLogout}
|
|
28
|
-
disabled={isPending}
|
|
29
|
-
variant='outline'>
|
|
30
|
-
{t('welcome.logout')}
|
|
31
|
-
</Button>
|
|
32
|
-
</div>
|
|
12
|
+
<div className='flex flex-col gap-6'>
|
|
13
|
+
<div>
|
|
14
|
+
<h1 className='text-3xl font-bold mb-4'>{t('app.welcome.title')}</h1>
|
|
15
|
+
<p className='text-muted-foreground'>{t('app.welcome.message')}</p>
|
|
33
16
|
</div>
|
|
34
17
|
</div>
|
|
35
18
|
);
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { createFileRoute, Outlet, redirect } from
|
|
2
|
-
import {
|
|
1
|
+
import { createFileRoute, Outlet, redirect } from '@tanstack/react-router';
|
|
2
|
+
import { AppLayout } from '@/modules/app/layouts/app-layout';
|
|
3
|
+
import { DEFAULT_NON_LOGGED_IN_ROUTE } from '@/lib/routes';
|
|
3
4
|
|
|
4
|
-
export const Route = createFileRoute(
|
|
5
|
+
export const Route = createFileRoute('/app')({
|
|
5
6
|
beforeLoad: ({ context }) => {
|
|
6
7
|
if (!context.token) {
|
|
7
8
|
throw redirect({
|
|
8
|
-
to:
|
|
9
|
+
to: DEFAULT_NON_LOGGED_IN_ROUTE,
|
|
9
10
|
});
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
|
-
component:
|
|
13
|
+
component: RouteComponent,
|
|
13
14
|
});
|
|
14
15
|
|
|
15
|
-
function
|
|
16
|
-
return
|
|
16
|
+
function RouteComponent() {
|
|
17
|
+
return (
|
|
18
|
+
<AppLayout>
|
|
19
|
+
<Outlet />
|
|
20
|
+
</AppLayout>
|
|
21
|
+
);
|
|
17
22
|
}
|
|
18
|
-
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
+
import { ForgotPasswordForm } from '@/modules/auth/components/forgot-password-form';
|
|
3
|
+
|
|
4
|
+
export const Route = createFileRoute("/auth/forgot-password")({
|
|
5
|
+
component: RouteComponent,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
function RouteComponent() {
|
|
9
|
+
return <ForgotPasswordForm />;
|
|
10
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { createFileRoute } from
|
|
2
|
-
import {
|
|
1
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
2
|
+
import { LoginForm } from '@/modules/auth/components/login-form';
|
|
3
3
|
|
|
4
|
-
export const Route = createFileRoute(
|
|
5
|
-
component:
|
|
4
|
+
export const Route = createFileRoute('/auth/login')({
|
|
5
|
+
component: RouteComponent,
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
return <
|
|
8
|
+
function RouteComponent() {
|
|
9
|
+
return <LoginForm />;
|
|
10
10
|
}
|
|
11
|
-
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
2
|
+
import { ResetPasswordForm } from '@/modules/auth/components/reset-password-form';
|
|
3
|
+
|
|
4
|
+
export const Route = createFileRoute('/auth/reset-password')({
|
|
5
|
+
component: RouteComponent,
|
|
6
|
+
validateSearch: (search: Record<string, unknown>) => {
|
|
7
|
+
return {
|
|
8
|
+
email: (search.email as string) || undefined,
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function RouteComponent() {
|
|
14
|
+
return <ResetPasswordForm />;
|
|
15
|
+
}
|
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import { createFileRoute, Outlet, redirect } from
|
|
2
|
-
import {
|
|
1
|
+
import { createFileRoute, Outlet, redirect, useNavigate } from '@tanstack/react-router';
|
|
2
|
+
import { AuthLayout } from '@/modules/auth/layouts/auth-layout';
|
|
3
|
+
import { DEFAULT_LOGGED_IN_ROUTE } from '@/lib/routes';
|
|
4
|
+
import { useAtomValue } from 'jotai';
|
|
5
|
+
import { authTokenAtom } from '@/modules/auth/hooks/use-auth-hook';
|
|
6
|
+
import { useEffect } from 'react';
|
|
3
7
|
|
|
4
|
-
export const Route = createFileRoute(
|
|
8
|
+
export const Route = createFileRoute('/auth')({
|
|
5
9
|
component: RouteComponent,
|
|
6
10
|
beforeLoad: ({ context }) => {
|
|
7
11
|
if (context.token) {
|
|
8
12
|
throw redirect({
|
|
9
|
-
to:
|
|
13
|
+
to: DEFAULT_LOGGED_IN_ROUTE,
|
|
10
14
|
});
|
|
11
15
|
}
|
|
12
16
|
},
|
|
13
17
|
});
|
|
14
18
|
|
|
15
19
|
function RouteComponent() {
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const token = useAtomValue(authTokenAtom);
|
|
21
|
+
const navigate = useNavigate();
|
|
22
|
+
|
|
23
|
+
// Navigate after successful authentication
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (token) {
|
|
26
|
+
navigate({ to: DEFAULT_LOGGED_IN_ROUTE, replace: true });
|
|
27
|
+
}
|
|
28
|
+
}, [token, navigate]);
|
|
18
29
|
|
|
30
|
+
return (
|
|
31
|
+
<AuthLayout>
|
|
32
|
+
<Outlet />
|
|
33
|
+
</AuthLayout>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
+
import { SignupForm } from '@/modules/auth/components/signup-form';
|
|
3
|
+
|
|
4
|
+
export const Route = createFileRoute("/auth/signup")({
|
|
5
|
+
component: RouteComponent,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
function RouteComponent() {
|
|
9
|
+
return <SignupForm />;
|
|
10
|
+
}
|
|
11
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { DefaultError, UseMutationOptions } from '@tanstack/react-query';
|
|
4
|
+
import type { AxiosError } from 'axios';
|
|
5
|
+
|
|
6
|
+
import { loginUserAuth, logoutUserAuth, type Options, registerUserAuth, resetPasswordUserAuth, sendOtpUserAuth, validateTokenUserAuth } from '../sdk.gen';
|
|
7
|
+
import type { LoginUserAuthData, LoginUserAuthResponse, LogoutUserAuthData, LogoutUserAuthResponse, RegisterUserAuthData, RegisterUserAuthResponse, ResetPasswordUserAuthData, ResetPasswordUserAuthResponse, SendOtpUserAuthData, SendOtpUserAuthResponse, ValidateTokenUserAuthData, ValidateTokenUserAuthResponse } from '../types.gen';
|
|
8
|
+
|
|
9
|
+
export const validateTokenUserAuthMutation = (options?: Partial<Options<ValidateTokenUserAuthData>>): UseMutationOptions<ValidateTokenUserAuthResponse, AxiosError<DefaultError>, Options<ValidateTokenUserAuthData>> => {
|
|
10
|
+
const mutationOptions: UseMutationOptions<ValidateTokenUserAuthResponse, AxiosError<DefaultError>, Options<ValidateTokenUserAuthData>> = {
|
|
11
|
+
mutationFn: async (fnOptions) => {
|
|
12
|
+
const { data } = await validateTokenUserAuth({
|
|
13
|
+
...options,
|
|
14
|
+
...fnOptions,
|
|
15
|
+
throwOnError: true
|
|
16
|
+
});
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return mutationOptions;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const sendOtpUserAuthMutation = (options?: Partial<Options<SendOtpUserAuthData>>): UseMutationOptions<SendOtpUserAuthResponse, AxiosError<DefaultError>, Options<SendOtpUserAuthData>> => {
|
|
24
|
+
const mutationOptions: UseMutationOptions<SendOtpUserAuthResponse, AxiosError<DefaultError>, Options<SendOtpUserAuthData>> = {
|
|
25
|
+
mutationFn: async (fnOptions) => {
|
|
26
|
+
const { data } = await sendOtpUserAuth({
|
|
27
|
+
...options,
|
|
28
|
+
...fnOptions,
|
|
29
|
+
throwOnError: true
|
|
30
|
+
});
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return mutationOptions;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const resetPasswordUserAuthMutation = (options?: Partial<Options<ResetPasswordUserAuthData>>): UseMutationOptions<ResetPasswordUserAuthResponse, AxiosError<DefaultError>, Options<ResetPasswordUserAuthData>> => {
|
|
38
|
+
const mutationOptions: UseMutationOptions<ResetPasswordUserAuthResponse, AxiosError<DefaultError>, Options<ResetPasswordUserAuthData>> = {
|
|
39
|
+
mutationFn: async (fnOptions) => {
|
|
40
|
+
const { data } = await resetPasswordUserAuth({
|
|
41
|
+
...options,
|
|
42
|
+
...fnOptions,
|
|
43
|
+
throwOnError: true
|
|
44
|
+
});
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return mutationOptions;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const registerUserAuthMutation = (options?: Partial<Options<RegisterUserAuthData>>): UseMutationOptions<RegisterUserAuthResponse, AxiosError<DefaultError>, Options<RegisterUserAuthData>> => {
|
|
52
|
+
const mutationOptions: UseMutationOptions<RegisterUserAuthResponse, AxiosError<DefaultError>, Options<RegisterUserAuthData>> = {
|
|
53
|
+
mutationFn: async (fnOptions) => {
|
|
54
|
+
const { data } = await registerUserAuth({
|
|
55
|
+
...options,
|
|
56
|
+
...fnOptions,
|
|
57
|
+
throwOnError: true
|
|
58
|
+
});
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return mutationOptions;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const logoutUserAuthMutation = (options?: Partial<Options<LogoutUserAuthData>>): UseMutationOptions<LogoutUserAuthResponse, AxiosError<DefaultError>, Options<LogoutUserAuthData>> => {
|
|
66
|
+
const mutationOptions: UseMutationOptions<LogoutUserAuthResponse, AxiosError<DefaultError>, Options<LogoutUserAuthData>> = {
|
|
67
|
+
mutationFn: async (fnOptions) => {
|
|
68
|
+
const { data } = await logoutUserAuth({
|
|
69
|
+
...options,
|
|
70
|
+
...fnOptions,
|
|
71
|
+
throwOnError: true
|
|
72
|
+
});
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return mutationOptions;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const loginUserAuthMutation = (options?: Partial<Options<LoginUserAuthData>>): UseMutationOptions<LoginUserAuthResponse, AxiosError<DefaultError>, Options<LoginUserAuthData>> => {
|
|
80
|
+
const mutationOptions: UseMutationOptions<LoginUserAuthResponse, AxiosError<DefaultError>, Options<LoginUserAuthData>> = {
|
|
81
|
+
mutationFn: async (fnOptions) => {
|
|
82
|
+
const { data } = await loginUserAuth({
|
|
83
|
+
...options,
|
|
84
|
+
...fnOptions,
|
|
85
|
+
throwOnError: true
|
|
86
|
+
});
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return mutationOptions;
|
|
91
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
|
|
6
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
7
|
+
import type { HttpMethod } from '../core/types.gen';
|
|
8
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
9
|
+
import type { Client, Config, RequestOptions } from './types.gen';
|
|
10
|
+
import {
|
|
11
|
+
buildUrl,
|
|
12
|
+
createConfig,
|
|
13
|
+
mergeConfigs,
|
|
14
|
+
mergeHeaders,
|
|
15
|
+
setAuthParams,
|
|
16
|
+
} from './utils.gen';
|
|
17
|
+
|
|
18
|
+
export const createClient = (config: Config = {}): Client => {
|
|
19
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
20
|
+
|
|
21
|
+
let instance: AxiosInstance;
|
|
22
|
+
|
|
23
|
+
if (_config.axios && !('Axios' in _config.axios)) {
|
|
24
|
+
instance = _config.axios;
|
|
25
|
+
} else {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
27
|
+
const { auth, ...configWithoutAuth } = _config;
|
|
28
|
+
instance = axios.create(configWithoutAuth);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const getConfig = (): Config => ({ ..._config });
|
|
32
|
+
|
|
33
|
+
const setConfig = (config: Config): Config => {
|
|
34
|
+
_config = mergeConfigs(_config, config);
|
|
35
|
+
instance.defaults = {
|
|
36
|
+
...instance.defaults,
|
|
37
|
+
..._config,
|
|
38
|
+
// @ts-expect-error
|
|
39
|
+
headers: mergeHeaders(instance.defaults.headers, _config.headers),
|
|
40
|
+
};
|
|
41
|
+
return getConfig();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
45
|
+
const opts = {
|
|
46
|
+
..._config,
|
|
47
|
+
...options,
|
|
48
|
+
axios: options.axios ?? _config.axios ?? instance,
|
|
49
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (opts.security) {
|
|
53
|
+
await setAuthParams({
|
|
54
|
+
...opts,
|
|
55
|
+
security: opts.security,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (opts.requestValidator) {
|
|
60
|
+
await opts.requestValidator(opts);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
64
|
+
opts.body = opts.bodySerializer(opts.body);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const url = buildUrl(opts);
|
|
68
|
+
|
|
69
|
+
return { opts, url };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
const request: Client['request'] = async (options) => {
|
|
74
|
+
// @ts-expect-error
|
|
75
|
+
const { opts, url } = await beforeRequest(options);
|
|
76
|
+
try {
|
|
77
|
+
// assign Axios here for consistency with fetch
|
|
78
|
+
const _axios = opts.axios!;
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
const { auth, ...optsWithoutAuth } = opts;
|
|
81
|
+
const response = await _axios({
|
|
82
|
+
...optsWithoutAuth,
|
|
83
|
+
baseURL: '', // the baseURL is already included in `url`
|
|
84
|
+
data: getValidRequestBody(opts),
|
|
85
|
+
headers: opts.headers as RawAxiosRequestHeaders,
|
|
86
|
+
// let `paramsSerializer()` handle query params if it exists
|
|
87
|
+
params: opts.paramsSerializer ? opts.query : undefined,
|
|
88
|
+
url,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let { data } = response;
|
|
92
|
+
|
|
93
|
+
if (opts.responseType === 'json') {
|
|
94
|
+
if (opts.responseValidator) {
|
|
95
|
+
await opts.responseValidator(data);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (opts.responseTransformer) {
|
|
99
|
+
data = await opts.responseTransformer(data);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
...response,
|
|
105
|
+
data: data ?? {},
|
|
106
|
+
};
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const e = error as AxiosError;
|
|
109
|
+
if (opts.throwOnError) {
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
// @ts-expect-error
|
|
113
|
+
e.error = e.response?.data ?? {};
|
|
114
|
+
return e;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const makeMethodFn =
|
|
119
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
120
|
+
request({ ...options, method });
|
|
121
|
+
|
|
122
|
+
const makeSseFn =
|
|
123
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
124
|
+
const { opts, url } = await beforeRequest(options);
|
|
125
|
+
return createSseClient({
|
|
126
|
+
...opts,
|
|
127
|
+
body: opts.body as BodyInit | null | undefined,
|
|
128
|
+
headers: opts.headers as Record<string, string>,
|
|
129
|
+
method,
|
|
130
|
+
serializedBody: getValidRequestBody(opts) as
|
|
131
|
+
| BodyInit
|
|
132
|
+
| null
|
|
133
|
+
| undefined,
|
|
134
|
+
// @ts-expect-error
|
|
135
|
+
signal: opts.signal,
|
|
136
|
+
url,
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
buildUrl,
|
|
142
|
+
connect: makeMethodFn('CONNECT'),
|
|
143
|
+
delete: makeMethodFn('DELETE'),
|
|
144
|
+
get: makeMethodFn('GET'),
|
|
145
|
+
getConfig,
|
|
146
|
+
head: makeMethodFn('HEAD'),
|
|
147
|
+
instance,
|
|
148
|
+
options: makeMethodFn('OPTIONS'),
|
|
149
|
+
patch: makeMethodFn('PATCH'),
|
|
150
|
+
post: makeMethodFn('POST'),
|
|
151
|
+
put: makeMethodFn('PUT'),
|
|
152
|
+
request,
|
|
153
|
+
setConfig,
|
|
154
|
+
sse: {
|
|
155
|
+
connect: makeSseFn('CONNECT'),
|
|
156
|
+
delete: makeSseFn('DELETE'),
|
|
157
|
+
get: makeSseFn('GET'),
|
|
158
|
+
head: makeSseFn('HEAD'),
|
|
159
|
+
options: makeSseFn('OPTIONS'),
|
|
160
|
+
patch: makeSseFn('PATCH'),
|
|
161
|
+
post: makeSseFn('POST'),
|
|
162
|
+
put: makeSseFn('PUT'),
|
|
163
|
+
trace: makeSseFn('TRACE'),
|
|
164
|
+
},
|
|
165
|
+
trace: makeMethodFn('TRACE'),
|
|
166
|
+
} as Client;
|
|
167
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type { Auth } from '../core/auth.gen';
|
|
4
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
5
|
+
export {
|
|
6
|
+
formDataBodySerializer,
|
|
7
|
+
jsonBodySerializer,
|
|
8
|
+
urlSearchParamsBodySerializer,
|
|
9
|
+
} from '../core/bodySerializer.gen';
|
|
10
|
+
export { buildClientParams } from '../core/params.gen';
|
|
11
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
12
|
+
export { createClient } from './client.gen';
|
|
13
|
+
export type {
|
|
14
|
+
Client,
|
|
15
|
+
ClientOptions,
|
|
16
|
+
Config,
|
|
17
|
+
CreateClientConfig,
|
|
18
|
+
Options,
|
|
19
|
+
RequestOptions,
|
|
20
|
+
RequestResult,
|
|
21
|
+
TDataShape,
|
|
22
|
+
} from './types.gen';
|
|
23
|
+
export { createConfig } from './utils.gen';
|