2f66fff993
Build & Push Docker Image / build (push) Failing after 1m18s
Policy: every direct dependency is now an exact pin; lockfile + --frozen-lockfile keep builds reproducible; save-exact=true enforced. Toolchain: - pnpm 10.26 -> 11.18 (lockfile migrated; supportedArchitectures moved to pnpm-workspace.yaml) - typescript 5.9 -> 7.0, vite 7 -> 8, @vitejs/plugin-react 5 -> 6 - esbuild override 0.27.3 -> 0.28.1 (closes GHSA-g7r4-m6w7-qqqr); added @esbuild/darwin-arm64 for local dev - orval 8.9 -> 8.23, regenerated clients Backend (prod image): - openid-client 5.7 -> 6.8 (rewritten OIDC flow in routes/auth.ts: discovery + functional API, PKCE/state, fetchUserInfo, buildEndSessionUrl) - pino 9 -> 10, pino-http 10 -> 11, thread-stream 3 -> 4 - zod 3.25 -> 4.4 (catalog; supported by drizzle-zod 0.8.3) - pg 8.20 -> 8.22; removed deprecated @types/bcryptjs Frontend: - react/react-dom 19.1.0 -> 19.2.8 (catalog pin lifted; expo note removed) - react-day-picker 9 -> 10 (table classname -> month_grid) - recharts 2 -> 3 (TooltipContentProps + DefaultLegendContentProps typing; safe keys) - react-resizable-panels 2 -> 4 (Group/Separator rename) - date-fns 3 -> 4, @hookform/resolvers 3 -> 5, lucide-react 0.545 -> 1.28 - all @radix-ui/*, tailwind, types, and remaining patch/minor deps bumped to latest Security/process: - overrides for body-parser >=2.3.0 (GHSA-v422-hmwv-36x6) + markdown-it/linkify-it/brace-expansion/fast-uri (dev tooling) - pnpm audit now reports 0 vulnerabilities (prod and full) - CI audit gate added to build.yaml; docs/dependency-policy.md; renovate.json - Dockerfile pins node:24.18.1-alpine and pnpm@11.18.0
2972 lines
83 KiB
TypeScript
2972 lines
83 KiB
TypeScript
/**
|
|
* Generated by orval v8.23.0 🍺
|
|
* Do not edit manually.
|
|
* Api
|
|
* ToolRate API — Tool listing and rating platform
|
|
* OpenAPI spec version: 0.1.0
|
|
*/
|
|
import {
|
|
useMutation,
|
|
useQuery
|
|
} from '@tanstack/react-query';
|
|
import type {
|
|
MutationFunction,
|
|
QueryFunction,
|
|
QueryKey,
|
|
UseMutationOptions,
|
|
UseMutationResult,
|
|
UseQueryOptions,
|
|
UseQueryResult
|
|
} from '@tanstack/react-query';
|
|
|
|
import type {
|
|
AnalyticsSummary,
|
|
AuditLog,
|
|
AuthMode,
|
|
AuthUser,
|
|
CategoryStats,
|
|
ChangePasswordInput,
|
|
CsrfToken,
|
|
EmptyTrash200,
|
|
ErrorResponse,
|
|
GetRatingDistributionParams,
|
|
GetTopToolsParams,
|
|
HealthStatus,
|
|
ListAuditLogsParams,
|
|
ListCompareToolsParams,
|
|
ListToolsParams,
|
|
ListTrashedToolsParams,
|
|
LocalLoginInput,
|
|
PasswordRedirect,
|
|
Rating,
|
|
RatingDistribution,
|
|
RatingHistoryItem,
|
|
RatingInput,
|
|
RestoreTools200,
|
|
SetPasswordInput,
|
|
Tool,
|
|
ToolInput,
|
|
ToolUpdate,
|
|
ToolWithStats,
|
|
TopToolEntry,
|
|
TrashTools200,
|
|
TrashToolsInput,
|
|
User,
|
|
UserCreateInput,
|
|
UserPreferences,
|
|
UserRoleUpdate,
|
|
VersionInfo
|
|
} from './api.schemas';
|
|
|
|
import { customFetch } from '../custom-fetch';
|
|
import type { ErrorType , BodyType } from '../custom-fetch';
|
|
|
|
type AwaitedInput<T> = PromiseLike<T> | T;
|
|
|
|
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
|
|
|
|
|
|
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
|
|
|
|
|
|
|
const withQueryKey = <T extends object, K>(query: T, queryKey: K): T & { queryKey: K } => {
|
|
const result = { queryKey } as T & { queryKey: K };
|
|
for (const key of Object.keys(query)) {
|
|
// The explicit queryKey always wins, matching the previous
|
|
// `{ ...query, queryKey }` spread where it was set last.
|
|
if (key === 'queryKey') continue;
|
|
Object.defineProperty(result, key, {
|
|
enumerable: true,
|
|
configurable: true,
|
|
get: () => (query as Record<string, unknown>)[key],
|
|
});
|
|
}
|
|
return result;
|
|
};
|
|
|
|
export const getHealthCheckUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/healthz`
|
|
}
|
|
|
|
/**
|
|
* Returns server health status
|
|
* @summary Health check
|
|
*/
|
|
export const healthCheck = async ( options?: Parameters<typeof customFetch>[1]): Promise<HealthStatus> => {
|
|
|
|
return customFetch<HealthStatus>(getHealthCheckUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getHealthCheckQueryKey = () => {
|
|
return [
|
|
`/api/healthz`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getHealthCheckQueryOptions = <TData = Awaited<ReturnType<typeof healthCheck>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getHealthCheckQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof healthCheck>>> = ({ signal }) => healthCheck({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type HealthCheckQueryResult = NonNullable<Awaited<ReturnType<typeof healthCheck>>>
|
|
export type HealthCheckQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Health check
|
|
*/
|
|
|
|
export function useHealthCheck<TData = Awaited<ReturnType<typeof healthCheck>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getHealthCheckQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetVersionUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/version`
|
|
}
|
|
|
|
/**
|
|
* Returns the running build version, commit SHA and build date
|
|
* @summary Build version information
|
|
*/
|
|
export const getVersion = async ( options?: Parameters<typeof customFetch>[1]): Promise<VersionInfo> => {
|
|
|
|
return customFetch<VersionInfo>(getGetVersionUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetVersionQueryKey = () => {
|
|
return [
|
|
`/api/version`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetVersionQueryOptions = <TData = Awaited<ReturnType<typeof getVersion>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getVersion>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetVersionQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getVersion>>> = ({ signal }) => getVersion({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getVersion>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetVersionQueryResult = NonNullable<Awaited<ReturnType<typeof getVersion>>>
|
|
export type GetVersionQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Build version information
|
|
*/
|
|
|
|
export function useGetVersion<TData = Awaited<ReturnType<typeof getVersion>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getVersion>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetVersionQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListToolsUrl = (params?: ListToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/tools?${stringifiedParams}` : `/api/tools`
|
|
}
|
|
|
|
/**
|
|
* @summary List all tools
|
|
*/
|
|
export const listTools = async (params?: ListToolsParams, options?: Parameters<typeof customFetch>[1]): Promise<ToolWithStats[]> => {
|
|
|
|
return customFetch<ToolWithStats[]>(getListToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListToolsQueryKey = (params?: ListToolsParams,) => {
|
|
return [
|
|
`/api/tools`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListToolsQueryOptions = <TData = Awaited<ReturnType<typeof listTools>>, TError = ErrorType<unknown>>(params?: ListToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listTools>>> = ({ signal }) => listTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListToolsQueryResult = NonNullable<Awaited<ReturnType<typeof listTools>>>
|
|
export type ListToolsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all tools
|
|
*/
|
|
|
|
export function useListTools<TData = Awaited<ReturnType<typeof listTools>>, TError = ErrorType<unknown>>(
|
|
params?: ListToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateToolUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools`
|
|
}
|
|
|
|
/**
|
|
* @summary Create a new tool
|
|
*/
|
|
export const createTool = async (toolInput: ToolInput, options?: Parameters<typeof customFetch>[1]): Promise<Tool> => {
|
|
|
|
return customFetch<Tool>(getCreateToolUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(toolInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateToolMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createTool>>, TError,{data: BodyType<ToolInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createTool>>, TError,{data: BodyType<ToolInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createTool'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createTool>>, {data: BodyType<ToolInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return createTool(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateToolMutationResult = NonNullable<Awaited<ReturnType<typeof createTool>>>
|
|
export type CreateToolMutationBody = BodyType<ToolInput>
|
|
export type CreateToolMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Create a new tool
|
|
*/
|
|
export const useCreateTool = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createTool>>, TError,{data: BodyType<ToolInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createTool>>,
|
|
TError,
|
|
{data: BodyType<ToolInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateToolMutationOptions(options));
|
|
}
|
|
|
|
export const getListCompareToolsUrl = (params: ListCompareToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/compare?${stringifiedParams}` : `/api/compare`
|
|
}
|
|
|
|
/**
|
|
* @summary Compare tools side by side (premium)
|
|
*/
|
|
export const listCompareTools = async (params: ListCompareToolsParams, options?: Parameters<typeof customFetch>[1]): Promise<ToolWithStats[]> => {
|
|
|
|
return customFetch<ToolWithStats[]>(getListCompareToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListCompareToolsQueryKey = (params?: ListCompareToolsParams,) => {
|
|
return [
|
|
`/api/compare`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListCompareToolsQueryOptions = <TData = Awaited<ReturnType<typeof listCompareTools>>, TError = ErrorType<ErrorResponse>>(params: ListCompareToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCompareTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListCompareToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listCompareTools>>> = ({ signal }) => listCompareTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listCompareTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListCompareToolsQueryResult = NonNullable<Awaited<ReturnType<typeof listCompareTools>>>
|
|
export type ListCompareToolsQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Compare tools side by side (premium)
|
|
*/
|
|
|
|
export function useListCompareTools<TData = Awaited<ReturnType<typeof listCompareTools>>, TError = ErrorType<ErrorResponse>>(
|
|
params: ListCompareToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCompareTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListCompareToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolRatingHistoryUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}/rating-history`
|
|
}
|
|
|
|
/**
|
|
* @summary Get a tool's rating history over time
|
|
*/
|
|
export const getToolRatingHistory = async (id: number, options?: Parameters<typeof customFetch>[1]): Promise<RatingHistoryItem[]> => {
|
|
|
|
return customFetch<RatingHistoryItem[]>(getGetToolRatingHistoryUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolRatingHistoryQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/tools/${id}/rating-history`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetToolRatingHistoryQueryOptions = <TData = Awaited<ReturnType<typeof getToolRatingHistory>>, TError = ErrorType<ErrorResponse>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getToolRatingHistory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetToolRatingHistoryQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getToolRatingHistory>>> = ({ signal }) => getToolRatingHistory(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: id !== null && id !== undefined, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getToolRatingHistory>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetToolRatingHistoryQueryResult = NonNullable<Awaited<ReturnType<typeof getToolRatingHistory>>>
|
|
export type GetToolRatingHistoryQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get a tool's rating history over time
|
|
*/
|
|
|
|
export function useGetToolRatingHistory<TData = Awaited<ReturnType<typeof getToolRatingHistory>>, TError = ErrorType<ErrorResponse>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getToolRatingHistory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetToolRatingHistoryQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Get a tool by ID
|
|
*/
|
|
export const getTool = async (id: number, options?: Parameters<typeof customFetch>[1]): Promise<ToolWithStats> => {
|
|
|
|
return customFetch<ToolWithStats>(getGetToolUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/tools/${id}`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetToolQueryOptions = <TData = Awaited<ReturnType<typeof getTool>>, TError = ErrorType<ErrorResponse>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTool>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetToolQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getTool>>> = ({ signal }) => getTool(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: id !== null && id !== undefined, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getTool>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetToolQueryResult = NonNullable<Awaited<ReturnType<typeof getTool>>>
|
|
export type GetToolQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get a tool by ID
|
|
*/
|
|
|
|
export function useGetTool<TData = Awaited<ReturnType<typeof getTool>>, TError = ErrorType<ErrorResponse>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTool>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetToolQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateToolUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update a tool
|
|
*/
|
|
export const updateTool = async (id: number,
|
|
toolUpdate: ToolUpdate, options?: Parameters<typeof customFetch>[1]): Promise<Tool> => {
|
|
|
|
return customFetch<Tool>(getUpdateToolUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(toolUpdate)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateToolMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateTool>>, TError,{id: number;data: BodyType<ToolUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateTool>>, TError,{id: number;data: BodyType<ToolUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updateTool'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateTool>>, {id: number;data: BodyType<ToolUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updateTool(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateToolMutationResult = NonNullable<Awaited<ReturnType<typeof updateTool>>>
|
|
export type UpdateToolMutationBody = BodyType<ToolUpdate>
|
|
export type UpdateToolMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Update a tool
|
|
*/
|
|
export const useUpdateTool = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateTool>>, TError,{id: number;data: BodyType<ToolUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateTool>>,
|
|
TError,
|
|
{id: number;data: BodyType<ToolUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateToolMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteToolUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Delete a tool
|
|
*/
|
|
export const deleteTool = async (id: number, options?: Parameters<typeof customFetch>[1]): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteToolUrl(id),
|
|
{
|
|
...options,
|
|
method: 'DELETE'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getDeleteToolMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTool>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteTool>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['deleteTool'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteTool>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return deleteTool(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteToolMutationResult = NonNullable<Awaited<ReturnType<typeof deleteTool>>>
|
|
|
|
export type DeleteToolMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Delete a tool
|
|
*/
|
|
export const useDeleteTool = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTool>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteTool>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteToolMutationOptions(options));
|
|
}
|
|
|
|
export const getListTrashedToolsUrl = (params?: ListTrashedToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/tools/trash?${stringifiedParams}` : `/api/tools/trash`
|
|
}
|
|
|
|
/**
|
|
* @summary List trashed (soft-deleted) tools
|
|
*/
|
|
export const listTrashedTools = async (params?: ListTrashedToolsParams, options?: Parameters<typeof customFetch>[1]): Promise<Tool[]> => {
|
|
|
|
return customFetch<Tool[]>(getListTrashedToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListTrashedToolsQueryKey = (params?: ListTrashedToolsParams,) => {
|
|
return [
|
|
`/api/tools/trash`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListTrashedToolsQueryOptions = <TData = Awaited<ReturnType<typeof listTrashedTools>>, TError = ErrorType<ErrorResponse>>(params?: ListTrashedToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTrashedTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListTrashedToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listTrashedTools>>> = ({ signal }) => listTrashedTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listTrashedTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListTrashedToolsQueryResult = NonNullable<Awaited<ReturnType<typeof listTrashedTools>>>
|
|
export type ListTrashedToolsQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary List trashed (soft-deleted) tools
|
|
*/
|
|
|
|
export function useListTrashedTools<TData = Awaited<ReturnType<typeof listTrashedTools>>, TError = ErrorType<ErrorResponse>>(
|
|
params?: ListTrashedToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTrashedTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListTrashedToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getTrashToolsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash`
|
|
}
|
|
|
|
/**
|
|
* @summary Move tools to trash (admin)
|
|
*/
|
|
export const trashTools = async (trashToolsInput: TrashToolsInput, options?: Parameters<typeof customFetch>[1]): Promise<TrashTools200> => {
|
|
|
|
return customFetch<TrashTools200>(getTrashToolsUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(trashToolsInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getTrashToolsMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof trashTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof trashTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['trashTools'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof trashTools>>, {data: BodyType<TrashToolsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return trashTools(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type TrashToolsMutationResult = NonNullable<Awaited<ReturnType<typeof trashTools>>>
|
|
export type TrashToolsMutationBody = BodyType<TrashToolsInput>
|
|
export type TrashToolsMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Move tools to trash (admin)
|
|
*/
|
|
export const useTrashTools = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof trashTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof trashTools>>,
|
|
TError,
|
|
{data: BodyType<TrashToolsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getTrashToolsMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteTrashedToolsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash`
|
|
}
|
|
|
|
/**
|
|
* @summary Permanently delete trashed tools (admin)
|
|
*/
|
|
export const deleteTrashedTools = async (trashToolsInput: TrashToolsInput, options?: Parameters<typeof customFetch>[1]): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteTrashedToolsUrl(),
|
|
{
|
|
...options,
|
|
method: 'DELETE',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(trashToolsInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getDeleteTrashedToolsMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTrashedTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteTrashedTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['deleteTrashedTools'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteTrashedTools>>, {data: BodyType<TrashToolsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return deleteTrashedTools(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteTrashedToolsMutationResult = NonNullable<Awaited<ReturnType<typeof deleteTrashedTools>>>
|
|
export type DeleteTrashedToolsMutationBody = BodyType<TrashToolsInput>
|
|
export type DeleteTrashedToolsMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Permanently delete trashed tools (admin)
|
|
*/
|
|
export const useDeleteTrashedTools = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTrashedTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteTrashedTools>>,
|
|
TError,
|
|
{data: BodyType<TrashToolsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteTrashedToolsMutationOptions(options));
|
|
}
|
|
|
|
export const getRestoreToolsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash/restore`
|
|
}
|
|
|
|
/**
|
|
* @summary Restore trashed tools
|
|
*/
|
|
export const restoreTools = async (trashToolsInput: TrashToolsInput, options?: Parameters<typeof customFetch>[1]): Promise<RestoreTools200> => {
|
|
|
|
return customFetch<RestoreTools200>(getRestoreToolsUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(trashToolsInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getRestoreToolsMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof restoreTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof restoreTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['restoreTools'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof restoreTools>>, {data: BodyType<TrashToolsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return restoreTools(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type RestoreToolsMutationResult = NonNullable<Awaited<ReturnType<typeof restoreTools>>>
|
|
export type RestoreToolsMutationBody = BodyType<TrashToolsInput>
|
|
export type RestoreToolsMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Restore trashed tools
|
|
*/
|
|
export const useRestoreTools = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof restoreTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof restoreTools>>,
|
|
TError,
|
|
{data: BodyType<TrashToolsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getRestoreToolsMutationOptions(options));
|
|
}
|
|
|
|
export const getEmptyTrashUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash/empty`
|
|
}
|
|
|
|
/**
|
|
* @summary Permanently delete all trashed tools (admin)
|
|
*/
|
|
export const emptyTrash = async ( options?: Parameters<typeof customFetch>[1]): Promise<EmptyTrash200> => {
|
|
|
|
return customFetch<EmptyTrash200>(getEmptyTrashUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getEmptyTrashMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof emptyTrash>>, TError,void, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof emptyTrash>>, TError,void, TContext> => {
|
|
|
|
const mutationKey = ['emptyTrash'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof emptyTrash>>, void> = () => {
|
|
|
|
|
|
return emptyTrash(requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type EmptyTrashMutationResult = NonNullable<Awaited<ReturnType<typeof emptyTrash>>>
|
|
|
|
export type EmptyTrashMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Permanently delete all trashed tools (admin)
|
|
*/
|
|
export const useEmptyTrash = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof emptyTrash>>, TError,void, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof emptyTrash>>,
|
|
TError,
|
|
void,
|
|
TContext
|
|
> => {
|
|
return useMutation(getEmptyTrashMutationOptions(options));
|
|
}
|
|
|
|
export const getListToolRatingsUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}/ratings`
|
|
}
|
|
|
|
/**
|
|
* @summary List ratings for a tool
|
|
*/
|
|
export const listToolRatings = async (id: number, options?: Parameters<typeof customFetch>[1]): Promise<Rating[]> => {
|
|
|
|
return customFetch<Rating[]>(getListToolRatingsUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListToolRatingsQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/tools/${id}/ratings`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListToolRatingsQueryOptions = <TData = Awaited<ReturnType<typeof listToolRatings>>, TError = ErrorType<unknown>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listToolRatings>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListToolRatingsQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listToolRatings>>> = ({ signal }) => listToolRatings(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: id !== null && id !== undefined, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listToolRatings>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListToolRatingsQueryResult = NonNullable<Awaited<ReturnType<typeof listToolRatings>>>
|
|
export type ListToolRatingsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List ratings for a tool
|
|
*/
|
|
|
|
export function useListToolRatings<TData = Awaited<ReturnType<typeof listToolRatings>>, TError = ErrorType<unknown>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listToolRatings>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListToolRatingsQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateRatingUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}/ratings`
|
|
}
|
|
|
|
/**
|
|
* @summary Submit a rating for a tool
|
|
*/
|
|
export const createRating = async (id: number,
|
|
ratingInput: RatingInput, options?: Parameters<typeof customFetch>[1]): Promise<Rating> => {
|
|
|
|
return customFetch<Rating>(getCreateRatingUrl(id),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(ratingInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateRatingMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createRating>>, TError,{id: number;data: BodyType<RatingInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createRating>>, TError,{id: number;data: BodyType<RatingInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createRating'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createRating>>, {id: number;data: BodyType<RatingInput>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return createRating(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateRatingMutationResult = NonNullable<Awaited<ReturnType<typeof createRating>>>
|
|
export type CreateRatingMutationBody = BodyType<RatingInput>
|
|
export type CreateRatingMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Submit a rating for a tool
|
|
*/
|
|
export const useCreateRating = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createRating>>, TError,{id: number;data: BodyType<RatingInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createRating>>,
|
|
TError,
|
|
{id: number;data: BodyType<RatingInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateRatingMutationOptions(options));
|
|
}
|
|
|
|
export const getGetAnalyticsSummaryUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/analytics/summary`
|
|
}
|
|
|
|
/**
|
|
* @summary Overall platform statistics
|
|
*/
|
|
export const getAnalyticsSummary = async ( options?: Parameters<typeof customFetch>[1]): Promise<AnalyticsSummary> => {
|
|
|
|
return customFetch<AnalyticsSummary>(getGetAnalyticsSummaryUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAnalyticsSummaryQueryKey = () => {
|
|
return [
|
|
`/api/analytics/summary`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetAnalyticsSummaryQueryOptions = <TData = Awaited<ReturnType<typeof getAnalyticsSummary>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsSummary>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetAnalyticsSummaryQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAnalyticsSummary>>> = ({ signal }) => getAnalyticsSummary({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsSummary>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetAnalyticsSummaryQueryResult = NonNullable<Awaited<ReturnType<typeof getAnalyticsSummary>>>
|
|
export type GetAnalyticsSummaryQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Overall platform statistics
|
|
*/
|
|
|
|
export function useGetAnalyticsSummary<TData = Awaited<ReturnType<typeof getAnalyticsSummary>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsSummary>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetAnalyticsSummaryQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetTopToolsUrl = (params?: GetTopToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/analytics/top-tools?${stringifiedParams}` : `/api/analytics/top-tools`
|
|
}
|
|
|
|
/**
|
|
* @summary Top-rated tools
|
|
*/
|
|
export const getTopTools = async (params?: GetTopToolsParams, options?: Parameters<typeof customFetch>[1]): Promise<TopToolEntry[]> => {
|
|
|
|
return customFetch<TopToolEntry[]>(getGetTopToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetTopToolsQueryKey = (params?: GetTopToolsParams,) => {
|
|
return [
|
|
`/api/analytics/top-tools`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetTopToolsQueryOptions = <TData = Awaited<ReturnType<typeof getTopTools>>, TError = ErrorType<unknown>>(params?: GetTopToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTopTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetTopToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getTopTools>>> = ({ signal }) => getTopTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getTopTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetTopToolsQueryResult = NonNullable<Awaited<ReturnType<typeof getTopTools>>>
|
|
export type GetTopToolsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Top-rated tools
|
|
*/
|
|
|
|
export function useGetTopTools<TData = Awaited<ReturnType<typeof getTopTools>>, TError = ErrorType<unknown>>(
|
|
params?: GetTopToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTopTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetTopToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAnalyticsByCategoryUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/analytics/by-category`
|
|
}
|
|
|
|
/**
|
|
* @summary Rating statistics grouped by category
|
|
*/
|
|
export const getAnalyticsByCategory = async ( options?: Parameters<typeof customFetch>[1]): Promise<CategoryStats[]> => {
|
|
|
|
return customFetch<CategoryStats[]>(getGetAnalyticsByCategoryUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAnalyticsByCategoryQueryKey = () => {
|
|
return [
|
|
`/api/analytics/by-category`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetAnalyticsByCategoryQueryOptions = <TData = Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetAnalyticsByCategoryQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAnalyticsByCategory>>> = ({ signal }) => getAnalyticsByCategory({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetAnalyticsByCategoryQueryResult = NonNullable<Awaited<ReturnType<typeof getAnalyticsByCategory>>>
|
|
export type GetAnalyticsByCategoryQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Rating statistics grouped by category
|
|
*/
|
|
|
|
export function useGetAnalyticsByCategory<TData = Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetAnalyticsByCategoryQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetRatingDistributionUrl = (params?: GetRatingDistributionParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/analytics/rating-distribution?${stringifiedParams}` : `/api/analytics/rating-distribution`
|
|
}
|
|
|
|
/**
|
|
* @summary Distribution of rating scores across the platform
|
|
*/
|
|
export const getRatingDistribution = async (params?: GetRatingDistributionParams, options?: Parameters<typeof customFetch>[1]): Promise<RatingDistribution> => {
|
|
|
|
return customFetch<RatingDistribution>(getGetRatingDistributionUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetRatingDistributionQueryKey = (params?: GetRatingDistributionParams,) => {
|
|
return [
|
|
`/api/analytics/rating-distribution`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetRatingDistributionQueryOptions = <TData = Awaited<ReturnType<typeof getRatingDistribution>>, TError = ErrorType<unknown>>(params?: GetRatingDistributionParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getRatingDistribution>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetRatingDistributionQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getRatingDistribution>>> = ({ signal }) => getRatingDistribution(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getRatingDistribution>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetRatingDistributionQueryResult = NonNullable<Awaited<ReturnType<typeof getRatingDistribution>>>
|
|
export type GetRatingDistributionQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Distribution of rating scores across the platform
|
|
*/
|
|
|
|
export function useGetRatingDistribution<TData = Awaited<ReturnType<typeof getRatingDistribution>>, TError = ErrorType<unknown>>(
|
|
params?: GetRatingDistributionParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getRatingDistribution>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetRatingDistributionQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListCategoriesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/categories`
|
|
}
|
|
|
|
/**
|
|
* @summary List all distinct tool categories
|
|
*/
|
|
export const listCategories = async ( options?: Parameters<typeof customFetch>[1]): Promise<string[]> => {
|
|
|
|
return customFetch<string[]>(getListCategoriesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListCategoriesQueryKey = () => {
|
|
return [
|
|
`/api/categories`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListCategoriesQueryOptions = <TData = Awaited<ReturnType<typeof listCategories>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCategories>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListCategoriesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listCategories>>> = ({ signal }) => listCategories({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listCategories>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListCategoriesQueryResult = NonNullable<Awaited<ReturnType<typeof listCategories>>>
|
|
export type ListCategoriesQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all distinct tool categories
|
|
*/
|
|
|
|
export function useListCategories<TData = Awaited<ReturnType<typeof listCategories>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCategories>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListCategoriesQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllFeaturesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/features/all`
|
|
}
|
|
|
|
/**
|
|
* @summary List all distinct feature strings across all tools
|
|
*/
|
|
export const listAllFeatures = async ( options?: Parameters<typeof customFetch>[1]): Promise<string[]> => {
|
|
|
|
return customFetch<string[]>(getListAllFeaturesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllFeaturesQueryKey = () => {
|
|
return [
|
|
`/api/features/all`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListAllFeaturesQueryOptions = <TData = Awaited<ReturnType<typeof listAllFeatures>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllFeatures>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListAllFeaturesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listAllFeatures>>> = ({ signal }) => listAllFeatures({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listAllFeatures>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListAllFeaturesQueryResult = NonNullable<Awaited<ReturnType<typeof listAllFeatures>>>
|
|
export type ListAllFeaturesQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all distinct feature strings across all tools
|
|
*/
|
|
|
|
export function useListAllFeatures<TData = Awaited<ReturnType<typeof listAllFeatures>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllFeatures>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListAllFeaturesQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllTagsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tags/all`
|
|
}
|
|
|
|
/**
|
|
* @summary List all distinct tag strings across all tools
|
|
*/
|
|
export const listAllTags = async ( options?: Parameters<typeof customFetch>[1]): Promise<string[]> => {
|
|
|
|
return customFetch<string[]>(getListAllTagsUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllTagsQueryKey = () => {
|
|
return [
|
|
`/api/tags/all`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListAllTagsQueryOptions = <TData = Awaited<ReturnType<typeof listAllTags>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllTags>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListAllTagsQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listAllTags>>> = ({ signal }) => listAllTags({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listAllTags>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListAllTagsQueryResult = NonNullable<Awaited<ReturnType<typeof listAllTags>>>
|
|
export type ListAllTagsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all distinct tag strings across all tools
|
|
*/
|
|
|
|
export function useListAllTags<TData = Awaited<ReturnType<typeof listAllTags>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllTags>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListAllTagsQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAuthModeUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/mode`
|
|
}
|
|
|
|
/**
|
|
* @summary Get authentication mode (oidc or local)
|
|
*/
|
|
export const getAuthMode = async ( options?: Parameters<typeof customFetch>[1]): Promise<AuthMode> => {
|
|
|
|
return customFetch<AuthMode>(getGetAuthModeUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAuthModeQueryKey = () => {
|
|
return [
|
|
`/api/auth/mode`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetAuthModeQueryOptions = <TData = Awaited<ReturnType<typeof getAuthMode>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAuthMode>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetAuthModeQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAuthMode>>> = ({ signal }) => getAuthMode({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAuthMode>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetAuthModeQueryResult = NonNullable<Awaited<ReturnType<typeof getAuthMode>>>
|
|
export type GetAuthModeQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Get authentication mode (oidc or local)
|
|
*/
|
|
|
|
export function useGetAuthMode<TData = Awaited<ReturnType<typeof getAuthMode>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAuthMode>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetAuthModeQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetCsrfTokenUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/csrf`
|
|
}
|
|
|
|
/**
|
|
* @summary Get a CSRF token for state-changing requests
|
|
*/
|
|
export const getCsrfToken = async ( options?: Parameters<typeof customFetch>[1]): Promise<CsrfToken> => {
|
|
|
|
return customFetch<CsrfToken>(getGetCsrfTokenUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetCsrfTokenQueryKey = () => {
|
|
return [
|
|
`/api/auth/csrf`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetCsrfTokenQueryOptions = <TData = Awaited<ReturnType<typeof getCsrfToken>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getCsrfToken>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetCsrfTokenQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getCsrfToken>>> = ({ signal }) => getCsrfToken({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getCsrfToken>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetCsrfTokenQueryResult = NonNullable<Awaited<ReturnType<typeof getCsrfToken>>>
|
|
export type GetCsrfTokenQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Get a CSRF token for state-changing requests
|
|
*/
|
|
|
|
export function useGetCsrfToken<TData = Awaited<ReturnType<typeof getCsrfToken>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getCsrfToken>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetCsrfTokenQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getLocalLoginUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/login`
|
|
}
|
|
|
|
/**
|
|
* @summary Local username/password login
|
|
*/
|
|
export const localLogin = async (localLoginInput: LocalLoginInput, options?: Parameters<typeof customFetch>[1]): Promise<AuthUser> => {
|
|
|
|
return customFetch<AuthUser>(getLocalLoginUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(localLoginInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getLocalLoginMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof localLogin>>, TError,{data: BodyType<LocalLoginInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof localLogin>>, TError,{data: BodyType<LocalLoginInput>}, TContext> => {
|
|
|
|
const mutationKey = ['localLogin'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof localLogin>>, {data: BodyType<LocalLoginInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return localLogin(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type LocalLoginMutationResult = NonNullable<Awaited<ReturnType<typeof localLogin>>>
|
|
export type LocalLoginMutationBody = BodyType<LocalLoginInput>
|
|
export type LocalLoginMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Local username/password login
|
|
*/
|
|
export const useLocalLogin = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof localLogin>>, TError,{data: BodyType<LocalLoginInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof localLogin>>,
|
|
TError,
|
|
{data: BodyType<LocalLoginInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getLocalLoginMutationOptions(options));
|
|
}
|
|
|
|
export const getGetMeUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me`
|
|
}
|
|
|
|
/**
|
|
* @summary Get current authenticated user
|
|
*/
|
|
export const getMe = async ( options?: Parameters<typeof customFetch>[1]): Promise<AuthUser> => {
|
|
|
|
return customFetch<AuthUser>(getGetMeUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMeQueryKey = () => {
|
|
return [
|
|
`/api/auth/me`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMeQueryOptions = <TData = Awaited<ReturnType<typeof getMe>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMeQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMe>>> = ({ signal }) => getMe({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMeQueryResult = NonNullable<Awaited<ReturnType<typeof getMe>>>
|
|
export type GetMeQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get current authenticated user
|
|
*/
|
|
|
|
export function useGetMe<TData = Awaited<ReturnType<typeof getMe>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMeQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getChangeMyPasswordUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/password`
|
|
}
|
|
|
|
/**
|
|
* @summary Change own password (local users only)
|
|
*/
|
|
export const changeMyPassword = async (changePasswordInput: ChangePasswordInput, options?: Parameters<typeof customFetch>[1]): Promise<void> => {
|
|
|
|
return customFetch<void>(getChangeMyPasswordUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(changePasswordInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getChangeMyPasswordMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof changeMyPassword>>, TError,{data: BodyType<ChangePasswordInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof changeMyPassword>>, TError,{data: BodyType<ChangePasswordInput>}, TContext> => {
|
|
|
|
const mutationKey = ['changeMyPassword'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof changeMyPassword>>, {data: BodyType<ChangePasswordInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return changeMyPassword(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type ChangeMyPasswordMutationResult = NonNullable<Awaited<ReturnType<typeof changeMyPassword>>>
|
|
export type ChangeMyPasswordMutationBody = BodyType<ChangePasswordInput>
|
|
export type ChangeMyPasswordMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Change own password (local users only)
|
|
*/
|
|
export const useChangeMyPassword = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof changeMyPassword>>, TError,{data: BodyType<ChangePasswordInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof changeMyPassword>>,
|
|
TError,
|
|
{data: BodyType<ChangePasswordInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getChangeMyPasswordMutationOptions(options));
|
|
}
|
|
|
|
export const getGetPasswordRedirectUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/password-redirect`
|
|
}
|
|
|
|
/**
|
|
* @summary Get redirect URL for managing credentials in the identity provider
|
|
*/
|
|
export const getPasswordRedirect = async ( options?: Parameters<typeof customFetch>[1]): Promise<PasswordRedirect> => {
|
|
|
|
return customFetch<PasswordRedirect>(getGetPasswordRedirectUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetPasswordRedirectQueryKey = () => {
|
|
return [
|
|
`/api/auth/password-redirect`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetPasswordRedirectQueryOptions = <TData = Awaited<ReturnType<typeof getPasswordRedirect>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getPasswordRedirect>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetPasswordRedirectQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPasswordRedirect>>> = ({ signal }) => getPasswordRedirect({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getPasswordRedirect>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetPasswordRedirectQueryResult = NonNullable<Awaited<ReturnType<typeof getPasswordRedirect>>>
|
|
export type GetPasswordRedirectQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Get redirect URL for managing credentials in the identity provider
|
|
*/
|
|
|
|
export function useGetPasswordRedirect<TData = Awaited<ReturnType<typeof getPasswordRedirect>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getPasswordRedirect>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetPasswordRedirectQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMePreferencesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/preferences`
|
|
}
|
|
|
|
/**
|
|
* @summary Get current user's browse preferences
|
|
*/
|
|
export const getMePreferences = async ( options?: Parameters<typeof customFetch>[1]): Promise<UserPreferences> => {
|
|
|
|
return customFetch<UserPreferences>(getGetMePreferencesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMePreferencesQueryKey = () => {
|
|
return [
|
|
`/api/auth/me/preferences`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMePreferencesQueryOptions = <TData = Awaited<ReturnType<typeof getMePreferences>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMePreferences>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMePreferencesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMePreferences>>> = ({ signal }) => getMePreferences({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMePreferences>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMePreferencesQueryResult = NonNullable<Awaited<ReturnType<typeof getMePreferences>>>
|
|
export type GetMePreferencesQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get current user's browse preferences
|
|
*/
|
|
|
|
export function useGetMePreferences<TData = Awaited<ReturnType<typeof getMePreferences>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMePreferences>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMePreferencesQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateMePreferencesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/preferences`
|
|
}
|
|
|
|
/**
|
|
* @summary Update current user's browse preferences
|
|
*/
|
|
export const updateMePreferences = async (userPreferences: UserPreferences, options?: Parameters<typeof customFetch>[1]): Promise<UserPreferences> => {
|
|
|
|
return customFetch<UserPreferences>(getUpdateMePreferencesUrl(),
|
|
{
|
|
...options,
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(userPreferences)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateMePreferencesMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateMePreferences>>, TError,{data: BodyType<UserPreferences>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateMePreferences>>, TError,{data: BodyType<UserPreferences>}, TContext> => {
|
|
|
|
const mutationKey = ['updateMePreferences'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateMePreferences>>, {data: BodyType<UserPreferences>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return updateMePreferences(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateMePreferencesMutationResult = NonNullable<Awaited<ReturnType<typeof updateMePreferences>>>
|
|
export type UpdateMePreferencesMutationBody = BodyType<UserPreferences>
|
|
export type UpdateMePreferencesMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Update current user's browse preferences
|
|
*/
|
|
export const useUpdateMePreferences = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateMePreferences>>, TError,{data: BodyType<UserPreferences>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateMePreferences>>,
|
|
TError,
|
|
{data: BodyType<UserPreferences>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateMePreferencesMutationOptions(options));
|
|
}
|
|
|
|
export const getGetMeWatchlistUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/watchlist`
|
|
}
|
|
|
|
/**
|
|
* @summary Get current user's watchlist tools (premium)
|
|
*/
|
|
export const getMeWatchlist = async ( options?: Parameters<typeof customFetch>[1]): Promise<ToolWithStats[]> => {
|
|
|
|
return customFetch<ToolWithStats[]>(getGetMeWatchlistUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMeWatchlistQueryKey = () => {
|
|
return [
|
|
`/api/auth/me/watchlist`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMeWatchlistQueryOptions = <TData = Awaited<ReturnType<typeof getMeWatchlist>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMeWatchlist>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMeWatchlistQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMeWatchlist>>> = ({ signal }) => getMeWatchlist({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMeWatchlist>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMeWatchlistQueryResult = NonNullable<Awaited<ReturnType<typeof getMeWatchlist>>>
|
|
export type GetMeWatchlistQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get current user's watchlist tools (premium)
|
|
*/
|
|
|
|
export function useGetMeWatchlist<TData = Awaited<ReturnType<typeof getMeWatchlist>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMeWatchlist>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMeWatchlistQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListUsersUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/users`
|
|
}
|
|
|
|
/**
|
|
* @summary List all local users (admin only)
|
|
*/
|
|
export const listUsers = async ( options?: Parameters<typeof customFetch>[1]): Promise<User[]> => {
|
|
|
|
return customFetch<User[]>(getListUsersUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListUsersQueryKey = () => {
|
|
return [
|
|
`/api/users`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListUsersQueryOptions = <TData = Awaited<ReturnType<typeof listUsers>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listUsers>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListUsersQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listUsers>>> = ({ signal }) => listUsers({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listUsers>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListUsersQueryResult = NonNullable<Awaited<ReturnType<typeof listUsers>>>
|
|
export type ListUsersQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary List all local users (admin only)
|
|
*/
|
|
|
|
export function useListUsers<TData = Awaited<ReturnType<typeof listUsers>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listUsers>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListUsersQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateUserUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/users`
|
|
}
|
|
|
|
/**
|
|
* @summary Create a new local user (admin only)
|
|
*/
|
|
export const createUser = async (userCreateInput: UserCreateInput, options?: Parameters<typeof customFetch>[1]): Promise<User> => {
|
|
|
|
return customFetch<User>(getCreateUserUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(userCreateInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateUserMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<UserCreateInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<UserCreateInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createUser'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUser>>, {data: BodyType<UserCreateInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return createUser(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateUserMutationResult = NonNullable<Awaited<ReturnType<typeof createUser>>>
|
|
export type CreateUserMutationBody = BodyType<UserCreateInput>
|
|
export type CreateUserMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Create a new local user (admin only)
|
|
*/
|
|
export const useCreateUser = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<UserCreateInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createUser>>,
|
|
TError,
|
|
{data: BodyType<UserCreateInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateUserMutationOptions(options));
|
|
}
|
|
|
|
export const getUpdateUserUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/users/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update user role (admin only)
|
|
*/
|
|
export const updateUser = async (id: number,
|
|
userRoleUpdate: UserRoleUpdate, options?: Parameters<typeof customFetch>[1]): Promise<User> => {
|
|
|
|
return customFetch<User>(getUpdateUserUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(userRoleUpdate)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateUserMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{id: number;data: BodyType<UserRoleUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{id: number;data: BodyType<UserRoleUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updateUser'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateUser>>, {id: number;data: BodyType<UserRoleUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updateUser(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateUserMutationResult = NonNullable<Awaited<ReturnType<typeof updateUser>>>
|
|
export type UpdateUserMutationBody = BodyType<UserRoleUpdate>
|
|
export type UpdateUserMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Update user role (admin only)
|
|
*/
|
|
export const useUpdateUser = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{id: number;data: BodyType<UserRoleUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateUser>>,
|
|
TError,
|
|
{id: number;data: BodyType<UserRoleUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateUserMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteUserUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/users/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Delete a user (admin only)
|
|
*/
|
|
export const deleteUser = async (id: number, options?: Parameters<typeof customFetch>[1]): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteUserUrl(id),
|
|
{
|
|
...options,
|
|
method: 'DELETE'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getDeleteUserMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['deleteUser'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteUser>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return deleteUser(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteUserMutationResult = NonNullable<Awaited<ReturnType<typeof deleteUser>>>
|
|
|
|
export type DeleteUserMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Delete a user (admin only)
|
|
*/
|
|
export const useDeleteUser = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteUser>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteUserMutationOptions(options));
|
|
}
|
|
|
|
export const getSetUserPasswordUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/users/${id}/password`
|
|
}
|
|
|
|
/**
|
|
* @summary Set/reset a user's password (admin only, local users only)
|
|
*/
|
|
export const setUserPassword = async (id: number,
|
|
setPasswordInput: SetPasswordInput, options?: Parameters<typeof customFetch>[1]): Promise<void> => {
|
|
|
|
return customFetch<void>(getSetUserPasswordUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(setPasswordInput)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getSetUserPasswordMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof setUserPassword>>, TError,{id: number;data: BodyType<SetPasswordInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof setUserPassword>>, TError,{id: number;data: BodyType<SetPasswordInput>}, TContext> => {
|
|
|
|
const mutationKey = ['setUserPassword'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof setUserPassword>>, {id: number;data: BodyType<SetPasswordInput>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return setUserPassword(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type SetUserPasswordMutationResult = NonNullable<Awaited<ReturnType<typeof setUserPassword>>>
|
|
export type SetUserPasswordMutationBody = BodyType<SetPasswordInput>
|
|
export type SetUserPasswordMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Set/reset a user's password (admin only, local users only)
|
|
*/
|
|
export const useSetUserPassword = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof setUserPassword>>, TError,{id: number;data: BodyType<SetPasswordInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof setUserPassword>>,
|
|
TError,
|
|
{id: number;data: BodyType<SetPasswordInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getSetUserPasswordMutationOptions(options));
|
|
}
|
|
|
|
export const getListAuditLogsUrl = (params?: ListAuditLogsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : String(value))
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/audit-logs?${stringifiedParams}` : `/api/audit-logs`
|
|
}
|
|
|
|
/**
|
|
* @summary List audit log entries (admin only)
|
|
*/
|
|
export const listAuditLogs = async (params?: ListAuditLogsParams, options?: Parameters<typeof customFetch>[1]): Promise<AuditLog[]> => {
|
|
|
|
return customFetch<AuditLog[]>(getListAuditLogsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAuditLogsQueryKey = (params?: ListAuditLogsParams,) => {
|
|
return [
|
|
`/api/audit-logs`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListAuditLogsQueryOptions = <TData = Awaited<ReturnType<typeof listAuditLogs>>, TError = ErrorType<unknown>>(params?: ListAuditLogsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAuditLogs>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListAuditLogsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listAuditLogs>>> = ({ signal }) => listAuditLogs(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listAuditLogs>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListAuditLogsQueryResult = NonNullable<Awaited<ReturnType<typeof listAuditLogs>>>
|
|
export type ListAuditLogsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List audit log entries (admin only)
|
|
*/
|
|
|
|
export function useListAuditLogs<TData = Awaited<ReturnType<typeof listAuditLogs>>, TError = ErrorType<unknown>>(
|
|
params?: ListAuditLogsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAuditLogs>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListAuditLogsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return withQueryKey(query, queryOptions.queryKey);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|