Spaces:
Sleeping
Sleeping
| /** | |
| * Generated by orval v8.5.3 🍺 | |
| * Do not edit manually. | |
| * Api | |
| * Guardian Agent API — dark pattern detection and checkout protection | |
| * 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 { | |
| ClassifyUpsellBody, | |
| CreateReportBody, | |
| DarkPatternReport, | |
| DemoScanBody, | |
| DemoScanResult, | |
| DetectDarkPatternsBody, | |
| DetectionReport, | |
| DomainOffenderSummary, | |
| ErrorResponse, | |
| FeeEstimateBody, | |
| FeeEstimateResult, | |
| GetTopOffendersParams, | |
| HealthStatus, | |
| ListReportsParams, | |
| PatternBreakdown, | |
| StatsSummary, | |
| TrustRating, | |
| UpsellClassification, | |
| UpsertTrustRatingBody, | |
| } 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]; | |
| /** | |
| * Returns server health status | |
| * @summary Health check | |
| */ | |
| export const getHealthCheckUrl = () => { | |
| return `/api/healthz`; | |
| }; | |
| export const healthCheck = async ( | |
| options?: RequestInit, | |
| ): 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 { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Analyzes page content for dark patterns using AI classification | |
| * @summary Detect dark patterns on a page | |
| */ | |
| export const getDetectDarkPatternsUrl = () => { | |
| return `/api/analysis/detect`; | |
| }; | |
| export const detectDarkPatterns = async ( | |
| detectDarkPatternsBody: DetectDarkPatternsBody, | |
| options?: RequestInit, | |
| ): Promise<DarkPatternReport> => { | |
| return customFetch<DarkPatternReport>(getDetectDarkPatternsUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(detectDarkPatternsBody), | |
| }); | |
| }; | |
| export const getDetectDarkPatternsMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof detectDarkPatterns>>, | |
| TError, | |
| { data: BodyType<DetectDarkPatternsBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof detectDarkPatterns>>, | |
| TError, | |
| { data: BodyType<DetectDarkPatternsBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["detectDarkPatterns"]; | |
| 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 detectDarkPatterns>>, | |
| { data: BodyType<DetectDarkPatternsBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return detectDarkPatterns(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type DetectDarkPatternsMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof detectDarkPatterns>> | |
| >; | |
| export type DetectDarkPatternsMutationBody = BodyType<DetectDarkPatternsBody>; | |
| export type DetectDarkPatternsMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Detect dark patterns on a page | |
| */ | |
| export const useDetectDarkPatterns = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof detectDarkPatterns>>, | |
| TError, | |
| { data: BodyType<DetectDarkPatternsBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof detectDarkPatterns>>, | |
| TError, | |
| { data: BodyType<DetectDarkPatternsBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getDetectDarkPatternsMutationOptions(options)); | |
| }; | |
| /** | |
| * Identifies what type of upsell/add-on screen is being shown | |
| * @summary Classify an upsell page type | |
| */ | |
| export const getClassifyUpsellUrl = () => { | |
| return `/api/analysis/classify-upsell`; | |
| }; | |
| export const classifyUpsell = async ( | |
| classifyUpsellBody: ClassifyUpsellBody, | |
| options?: RequestInit, | |
| ): Promise<UpsellClassification> => { | |
| return customFetch<UpsellClassification>(getClassifyUpsellUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(classifyUpsellBody), | |
| }); | |
| }; | |
| export const getClassifyUpsellMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof classifyUpsell>>, | |
| TError, | |
| { data: BodyType<ClassifyUpsellBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof classifyUpsell>>, | |
| TError, | |
| { data: BodyType<ClassifyUpsellBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["classifyUpsell"]; | |
| 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 classifyUpsell>>, | |
| { data: BodyType<ClassifyUpsellBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return classifyUpsell(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type ClassifyUpsellMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof classifyUpsell>> | |
| >; | |
| export type ClassifyUpsellMutationBody = BodyType<ClassifyUpsellBody>; | |
| export type ClassifyUpsellMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Classify an upsell page type | |
| */ | |
| export const useClassifyUpsell = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof classifyUpsell>>, | |
| TError, | |
| { data: BodyType<ClassifyUpsellBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof classifyUpsell>>, | |
| TError, | |
| { data: BodyType<ClassifyUpsellBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getClassifyUpsellMutationOptions(options)); | |
| }; | |
| /** | |
| * Returns trust ratings for all tracked domains | |
| * @summary List all site trust ratings | |
| */ | |
| export const getListTrustRatingsUrl = () => { | |
| return `/api/trust`; | |
| }; | |
| export const listTrustRatings = async ( | |
| options?: RequestInit, | |
| ): Promise<TrustRating[]> => { | |
| return customFetch<TrustRating[]>(getListTrustRatingsUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListTrustRatingsQueryKey = () => { | |
| return [`/api/trust`] as const; | |
| }; | |
| export const getListTrustRatingsQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listTrustRatings>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listTrustRatings>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListTrustRatingsQueryKey(); | |
| const queryFn: QueryFunction< | |
| Awaited<ReturnType<typeof listTrustRatings>> | |
| > = ({ signal }) => listTrustRatings({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listTrustRatings>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListTrustRatingsQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listTrustRatings>> | |
| >; | |
| export type ListTrustRatingsQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List all site trust ratings | |
| */ | |
| export function useListTrustRatings< | |
| TData = Awaited<ReturnType<typeof listTrustRatings>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listTrustRatings>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListTrustRatingsQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Returns the trust rating and history for a specific domain | |
| * @summary Get trust rating for a domain | |
| */ | |
| export const getGetTrustRatingUrl = (domain: string) => { | |
| return `/api/trust/${domain}`; | |
| }; | |
| export const getTrustRating = async ( | |
| domain: string, | |
| options?: RequestInit, | |
| ): Promise<TrustRating> => { | |
| return customFetch<TrustRating>(getGetTrustRatingUrl(domain), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetTrustRatingQueryKey = (domain: string) => { | |
| return [`/api/trust/${domain}`] as const; | |
| }; | |
| export const getGetTrustRatingQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getTrustRating>>, | |
| TError = ErrorType<ErrorResponse>, | |
| >( | |
| domain: string, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getTrustRating>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetTrustRatingQueryKey(domain); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getTrustRating>>> = ({ | |
| signal, | |
| }) => getTrustRating(domain, { signal, ...requestOptions }); | |
| return { | |
| queryKey, | |
| queryFn, | |
| enabled: !!domain, | |
| ...queryOptions, | |
| } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getTrustRating>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetTrustRatingQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getTrustRating>> | |
| >; | |
| export type GetTrustRatingQueryError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Get trust rating for a domain | |
| */ | |
| export function useGetTrustRating< | |
| TData = Awaited<ReturnType<typeof getTrustRating>>, | |
| TError = ErrorType<ErrorResponse>, | |
| >( | |
| domain: string, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getTrustRating>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetTrustRatingQueryOptions(domain, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Updates the trust rating after a checkout interaction | |
| * @summary Create or update trust rating for a domain | |
| */ | |
| export const getUpsertTrustRatingUrl = (domain: string) => { | |
| return `/api/trust/${domain}`; | |
| }; | |
| export const upsertTrustRating = async ( | |
| domain: string, | |
| upsertTrustRatingBody: UpsertTrustRatingBody, | |
| options?: RequestInit, | |
| ): Promise<TrustRating> => { | |
| return customFetch<TrustRating>(getUpsertTrustRatingUrl(domain), { | |
| ...options, | |
| method: "PUT", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(upsertTrustRatingBody), | |
| }); | |
| }; | |
| export const getUpsertTrustRatingMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof upsertTrustRating>>, | |
| TError, | |
| { domain: string; data: BodyType<UpsertTrustRatingBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof upsertTrustRating>>, | |
| TError, | |
| { domain: string; data: BodyType<UpsertTrustRatingBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["upsertTrustRating"]; | |
| 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 upsertTrustRating>>, | |
| { domain: string; data: BodyType<UpsertTrustRatingBody> } | |
| > = (props) => { | |
| const { domain, data } = props ?? {}; | |
| return upsertTrustRating(domain, data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type UpsertTrustRatingMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof upsertTrustRating>> | |
| >; | |
| export type UpsertTrustRatingMutationBody = BodyType<UpsertTrustRatingBody>; | |
| export type UpsertTrustRatingMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Create or update trust rating for a domain | |
| */ | |
| export const useUpsertTrustRating = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof upsertTrustRating>>, | |
| TError, | |
| { domain: string; data: BodyType<UpsertTrustRatingBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof upsertTrustRating>>, | |
| TError, | |
| { domain: string; data: BodyType<UpsertTrustRatingBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getUpsertTrustRatingMutationOptions(options)); | |
| }; | |
| /** | |
| * Returns recent dark pattern detection reports | |
| * @summary List detection reports | |
| */ | |
| export const getListReportsUrl = (params?: ListReportsParams) => { | |
| const normalizedParams = new URLSearchParams(); | |
| Object.entries(params || {}).forEach(([key, value]) => { | |
| if (value !== undefined) { | |
| normalizedParams.append(key, value === null ? "null" : value.toString()); | |
| } | |
| }); | |
| const stringifiedParams = normalizedParams.toString(); | |
| return stringifiedParams.length > 0 | |
| ? `/api/reports?${stringifiedParams}` | |
| : `/api/reports`; | |
| }; | |
| export const listReports = async ( | |
| params?: ListReportsParams, | |
| options?: RequestInit, | |
| ): Promise<DetectionReport[]> => { | |
| return customFetch<DetectionReport[]>(getListReportsUrl(params), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getListReportsQueryKey = (params?: ListReportsParams) => { | |
| return [`/api/reports`, ...(params ? [params] : [])] as const; | |
| }; | |
| export const getListReportsQueryOptions = < | |
| TData = Awaited<ReturnType<typeof listReports>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: ListReportsParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listReports>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getListReportsQueryKey(params); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof listReports>>> = ({ | |
| signal, | |
| }) => listReports(params, { signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof listReports>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type ListReportsQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof listReports>> | |
| >; | |
| export type ListReportsQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary List detection reports | |
| */ | |
| export function useListReports< | |
| TData = Awaited<ReturnType<typeof listReports>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: ListReportsParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof listReports>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getListReportsQueryOptions(params, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Stores a dark pattern detection report for a session | |
| * @summary Save a detection report | |
| */ | |
| export const getCreateReportUrl = () => { | |
| return `/api/reports`; | |
| }; | |
| export const createReport = async ( | |
| createReportBody: CreateReportBody, | |
| options?: RequestInit, | |
| ): Promise<DetectionReport> => { | |
| return customFetch<DetectionReport>(getCreateReportUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(createReportBody), | |
| }); | |
| }; | |
| export const getCreateReportMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof createReport>>, | |
| TError, | |
| { data: BodyType<CreateReportBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof createReport>>, | |
| TError, | |
| { data: BodyType<CreateReportBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["createReport"]; | |
| 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 createReport>>, | |
| { data: BodyType<CreateReportBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return createReport(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type CreateReportMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof createReport>> | |
| >; | |
| export type CreateReportMutationBody = BodyType<CreateReportBody>; | |
| export type CreateReportMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Save a detection report | |
| */ | |
| export const useCreateReport = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof createReport>>, | |
| TError, | |
| { data: BodyType<CreateReportBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof createReport>>, | |
| TError, | |
| { data: BodyType<CreateReportBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getCreateReportMutationOptions(options)); | |
| }; | |
| /** | |
| * @summary Get a detection report by ID | |
| */ | |
| export const getGetReportUrl = (id: number) => { | |
| return `/api/reports/${id}`; | |
| }; | |
| export const getReport = async ( | |
| id: number, | |
| options?: RequestInit, | |
| ): Promise<DetectionReport> => { | |
| return customFetch<DetectionReport>(getGetReportUrl(id), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetReportQueryKey = (id: number) => { | |
| return [`/api/reports/${id}`] as const; | |
| }; | |
| export const getGetReportQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getReport>>, | |
| TError = ErrorType<ErrorResponse>, | |
| >( | |
| id: number, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getReport>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetReportQueryKey(id); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getReport>>> = ({ | |
| signal, | |
| }) => getReport(id, { signal, ...requestOptions }); | |
| return { | |
| queryKey, | |
| queryFn, | |
| enabled: !!id, | |
| ...queryOptions, | |
| } as UseQueryOptions<Awaited<ReturnType<typeof getReport>>, TError, TData> & { | |
| queryKey: QueryKey; | |
| }; | |
| }; | |
| export type GetReportQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getReport>> | |
| >; | |
| export type GetReportQueryError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Get a detection report by ID | |
| */ | |
| export function useGetReport< | |
| TData = Awaited<ReturnType<typeof getReport>>, | |
| TError = ErrorType<ErrorResponse>, | |
| >( | |
| id: number, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getReport>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetReportQueryOptions(id, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Returns aggregated stats — total scans, patterns detected, money saved estimates | |
| * @summary Get overall statistics summary | |
| */ | |
| export const getGetStatsSummaryUrl = () => { | |
| return `/api/stats/summary`; | |
| }; | |
| export const getStatsSummary = async ( | |
| options?: RequestInit, | |
| ): Promise<StatsSummary> => { | |
| return customFetch<StatsSummary>(getGetStatsSummaryUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetStatsSummaryQueryKey = () => { | |
| return [`/api/stats/summary`] as const; | |
| }; | |
| export const getGetStatsSummaryQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getStatsSummary>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getStatsSummary>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetStatsSummaryQueryKey(); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getStatsSummary>>> = ({ | |
| signal, | |
| }) => getStatsSummary({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getStatsSummary>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetStatsSummaryQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getStatsSummary>> | |
| >; | |
| export type GetStatsSummaryQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get overall statistics summary | |
| */ | |
| export function useGetStatsSummary< | |
| TData = Awaited<ReturnType<typeof getStatsSummary>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getStatsSummary>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetStatsSummaryQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Returns counts by dark pattern type across all reports | |
| * @summary Get pattern detection breakdown | |
| */ | |
| export const getGetPatternBreakdownUrl = () => { | |
| return `/api/stats/pattern-breakdown`; | |
| }; | |
| export const getPatternBreakdown = async ( | |
| options?: RequestInit, | |
| ): Promise<PatternBreakdown> => { | |
| return customFetch<PatternBreakdown>(getGetPatternBreakdownUrl(), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetPatternBreakdownQueryKey = () => { | |
| return [`/api/stats/pattern-breakdown`] as const; | |
| }; | |
| export const getGetPatternBreakdownQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getPatternBreakdown>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getPatternBreakdown>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetPatternBreakdownQueryKey(); | |
| const queryFn: QueryFunction< | |
| Awaited<ReturnType<typeof getPatternBreakdown>> | |
| > = ({ signal }) => getPatternBreakdown({ signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getPatternBreakdown>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetPatternBreakdownQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getPatternBreakdown>> | |
| >; | |
| export type GetPatternBreakdownQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get pattern detection breakdown | |
| */ | |
| export function useGetPatternBreakdown< | |
| TData = Awaited<ReturnType<typeof getPatternBreakdown>>, | |
| TError = ErrorType<unknown>, | |
| >(options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getPatternBreakdown>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetPatternBreakdownQueryOptions(options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |
| /** | |
| * Detects dark patterns, saves report, and updates trust rating in one call. Perfect for live demos. | |
| * @summary All-in-one demo scan | |
| */ | |
| export const getDemoScanUrl = () => { | |
| return `/api/demo/scan`; | |
| }; | |
| export const demoScan = async ( | |
| demoScanBody: DemoScanBody, | |
| options?: RequestInit, | |
| ): Promise<DemoScanResult> => { | |
| return customFetch<DemoScanResult>(getDemoScanUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(demoScanBody), | |
| }); | |
| }; | |
| export const getDemoScanMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof demoScan>>, | |
| TError, | |
| { data: BodyType<DemoScanBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof demoScan>>, | |
| TError, | |
| { data: BodyType<DemoScanBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["demoScan"]; | |
| 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 demoScan>>, | |
| { data: BodyType<DemoScanBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return demoScan(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type DemoScanMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof demoScan>> | |
| >; | |
| export type DemoScanMutationBody = BodyType<DemoScanBody>; | |
| export type DemoScanMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary All-in-one demo scan | |
| */ | |
| export const useDemoScan = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof demoScan>>, | |
| TError, | |
| { data: BodyType<DemoScanBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof demoScan>>, | |
| TError, | |
| { data: BodyType<DemoScanBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getDemoScanMutationOptions(options)); | |
| }; | |
| /** | |
| * Uses AI to estimate hidden fees and total true price for a given site and listing price | |
| * @summary Estimate true final price | |
| */ | |
| export const getDemoFeeEstimateUrl = () => { | |
| return `/api/demo/fee-estimate`; | |
| }; | |
| export const demoFeeEstimate = async ( | |
| feeEstimateBody: FeeEstimateBody, | |
| options?: RequestInit, | |
| ): Promise<FeeEstimateResult> => { | |
| return customFetch<FeeEstimateResult>(getDemoFeeEstimateUrl(), { | |
| ...options, | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...options?.headers }, | |
| body: JSON.stringify(feeEstimateBody), | |
| }); | |
| }; | |
| export const getDemoFeeEstimateMutationOptions = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof demoFeeEstimate>>, | |
| TError, | |
| { data: BodyType<FeeEstimateBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationOptions< | |
| Awaited<ReturnType<typeof demoFeeEstimate>>, | |
| TError, | |
| { data: BodyType<FeeEstimateBody> }, | |
| TContext | |
| > => { | |
| const mutationKey = ["demoFeeEstimate"]; | |
| 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 demoFeeEstimate>>, | |
| { data: BodyType<FeeEstimateBody> } | |
| > = (props) => { | |
| const { data } = props ?? {}; | |
| return demoFeeEstimate(data, requestOptions); | |
| }; | |
| return { mutationFn, ...mutationOptions }; | |
| }; | |
| export type DemoFeeEstimateMutationResult = NonNullable< | |
| Awaited<ReturnType<typeof demoFeeEstimate>> | |
| >; | |
| export type DemoFeeEstimateMutationBody = BodyType<FeeEstimateBody>; | |
| export type DemoFeeEstimateMutationError = ErrorType<ErrorResponse>; | |
| /** | |
| * @summary Estimate true final price | |
| */ | |
| export const useDemoFeeEstimate = < | |
| TError = ErrorType<ErrorResponse>, | |
| TContext = unknown, | |
| >(options?: { | |
| mutation?: UseMutationOptions< | |
| Awaited<ReturnType<typeof demoFeeEstimate>>, | |
| TError, | |
| { data: BodyType<FeeEstimateBody> }, | |
| TContext | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }): UseMutationResult< | |
| Awaited<ReturnType<typeof demoFeeEstimate>>, | |
| TError, | |
| { data: BodyType<FeeEstimateBody> }, | |
| TContext | |
| > => { | |
| return useMutation(getDemoFeeEstimateMutationOptions(options)); | |
| }; | |
| /** | |
| * Returns the domains with the most detected dark patterns | |
| * @summary Get top offending domains | |
| */ | |
| export const getGetTopOffendersUrl = (params?: GetTopOffendersParams) => { | |
| const normalizedParams = new URLSearchParams(); | |
| Object.entries(params || {}).forEach(([key, value]) => { | |
| if (value !== undefined) { | |
| normalizedParams.append(key, value === null ? "null" : value.toString()); | |
| } | |
| }); | |
| const stringifiedParams = normalizedParams.toString(); | |
| return stringifiedParams.length > 0 | |
| ? `/api/stats/top-offenders?${stringifiedParams}` | |
| : `/api/stats/top-offenders`; | |
| }; | |
| export const getTopOffenders = async ( | |
| params?: GetTopOffendersParams, | |
| options?: RequestInit, | |
| ): Promise<DomainOffenderSummary[]> => { | |
| return customFetch<DomainOffenderSummary[]>(getGetTopOffendersUrl(params), { | |
| ...options, | |
| method: "GET", | |
| }); | |
| }; | |
| export const getGetTopOffendersQueryKey = (params?: GetTopOffendersParams) => { | |
| return [`/api/stats/top-offenders`, ...(params ? [params] : [])] as const; | |
| }; | |
| export const getGetTopOffendersQueryOptions = < | |
| TData = Awaited<ReturnType<typeof getTopOffenders>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: GetTopOffendersParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getTopOffenders>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ) => { | |
| const { query: queryOptions, request: requestOptions } = options ?? {}; | |
| const queryKey = queryOptions?.queryKey ?? getGetTopOffendersQueryKey(params); | |
| const queryFn: QueryFunction<Awaited<ReturnType<typeof getTopOffenders>>> = ({ | |
| signal, | |
| }) => getTopOffenders(params, { signal, ...requestOptions }); | |
| return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< | |
| Awaited<ReturnType<typeof getTopOffenders>>, | |
| TError, | |
| TData | |
| > & { queryKey: QueryKey }; | |
| }; | |
| export type GetTopOffendersQueryResult = NonNullable< | |
| Awaited<ReturnType<typeof getTopOffenders>> | |
| >; | |
| export type GetTopOffendersQueryError = ErrorType<unknown>; | |
| /** | |
| * @summary Get top offending domains | |
| */ | |
| export function useGetTopOffenders< | |
| TData = Awaited<ReturnType<typeof getTopOffenders>>, | |
| TError = ErrorType<unknown>, | |
| >( | |
| params?: GetTopOffendersParams, | |
| options?: { | |
| query?: UseQueryOptions< | |
| Awaited<ReturnType<typeof getTopOffenders>>, | |
| TError, | |
| TData | |
| >; | |
| request?: SecondParameter<typeof customFetch>; | |
| }, | |
| ): UseQueryResult<TData, TError> & { queryKey: QueryKey } { | |
| const queryOptions = getGetTopOffendersQueryOptions(params, options); | |
| const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { | |
| queryKey: QueryKey; | |
| }; | |
| return { ...query, queryKey: queryOptions.queryKey }; | |
| } | |