// This file is auto-generated by @hey-api/openapi-ts import { type InfiniteData, infiniteQueryOptions, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; import { client } from '../client.gen'; import { getAuthRedirect, getEventAttendance, getEventCheckin, getEventCheckinQuery, getEventInfo, getEventJoined, getEventList, getUserInfo, getUserInfoByUserId, getUserList, type Options, patchUserUpdate, postAgendaSubmit, postAuthExchange, postAuthMagic, postAuthRefresh, postAuthToken, postEventCheckinSubmit, postEventJoin, postKycQuery, postKycSession } from '../sdk.gen'; import type { GetAuthRedirectData, GetAuthRedirectError, GetEventAttendanceData, GetEventAttendanceError, GetEventAttendanceResponse, GetEventCheckinData, GetEventCheckinError, GetEventCheckinQueryData, GetEventCheckinQueryError, GetEventCheckinQueryResponse, GetEventCheckinResponse, GetEventInfoData, GetEventInfoError, GetEventInfoResponse, GetEventJoinedData, GetEventJoinedError, GetEventJoinedResponse, GetEventListData, GetEventListError, GetEventListResponse, GetUserInfoByUserIdData, GetUserInfoByUserIdError, GetUserInfoByUserIdResponse, GetUserInfoData, GetUserInfoError, GetUserInfoResponse, GetUserListData, GetUserListError, GetUserListResponse, PatchUserUpdateData, PatchUserUpdateError, PatchUserUpdateResponse, PostAgendaSubmitData, PostAgendaSubmitError, PostAgendaSubmitResponse, PostAuthExchangeData, PostAuthExchangeError, PostAuthExchangeResponse, PostAuthMagicData, PostAuthMagicError, PostAuthMagicResponse, PostAuthRefreshData, PostAuthRefreshError, PostAuthRefreshResponse, PostAuthTokenData, PostAuthTokenError, PostAuthTokenResponse, PostEventCheckinSubmitData, PostEventCheckinSubmitError, PostEventCheckinSubmitResponse, PostEventJoinData, PostEventJoinError, PostEventJoinResponse, PostKycQueryData, PostKycQueryError, PostKycQueryResponse, PostKycSessionData, PostKycSessionError, PostKycSessionResponse } from '../types.gen'; /** * Submit Agenda * * Creates a new agenda item for a specific attendance record. */ export const postAgendaSubmitMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postAgendaSubmit({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; /** * Exchange Auth Code * * Exchanges client credentials and user session for a specific redirect authorization code. */ export const postAuthExchangeMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postAuthExchange({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; /** * Request Magic Link * * Verifies Turnstile token and sends an authentication link via email. Returns the URI directly if debug mode is enabled. */ export const postAuthMagicMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postAuthMagic({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; export type QueryKey = [ Pick & { _id: string; _infinite?: boolean; tags?: ReadonlyArray; } ]; const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ QueryKey[0] ] => { const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; if (infinite) { params._infinite = infinite; } if (tags) { params.tags = tags; } if (options?.body) { params.body = options.body; } if (options?.headers) { params.headers = options.headers; } if (options?.path) { params.path = options.path; } if (options?.query) { params.query = options.query; } return [params]; }; export const getAuthRedirectQueryKey = (options: Options) => createQueryKey('getAuthRedirect', options); /** * Handle Auth Callback and Redirect * * Verifies the temporary email code, ensures the user exists (or creates one), validates the client's redirect URI, and finally performs a 302 redirect with a new authorization code. */ export const getAuthRedirectOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getAuthRedirect({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getAuthRedirectQueryKey(options) }); /** * Refresh Access Token * * Accepts a valid refresh token to issue a new access token and a rotated refresh token. */ export const postAuthRefreshMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postAuthRefresh({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; /** * Exchange Code for Token * * Verifies the provided authorization code and issues a pair of JWT tokens (Access and Refresh). */ export const postAuthTokenMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postAuthToken({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; export const getEventAttendanceQueryKey = (options: Options) => createQueryKey('getEventAttendance', options); /** * Get Attendance List * * Retrieves the list of attendees, including user info and decrypted KYC data for a specified event. */ export const getEventAttendanceOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getEventAttendance({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getEventAttendanceQueryKey(options) }); export const getEventCheckinQueryKey = (options: Options) => createQueryKey('getEventCheckin', options); /** * Generate Check-in Code * * Creates a temporary check-in code for the authenticated user and event. */ export const getEventCheckinOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getEventCheckin({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getEventCheckinQueryKey(options) }); export const getEventCheckinQueryQueryKey = (options: Options) => createQueryKey('getEventCheckinQuery', options); /** * Query Check-in Status * * Returns the timestamp of when the user checked in, or null if not yet checked in. */ export const getEventCheckinQueryOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getEventCheckinQuery({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getEventCheckinQueryQueryKey(options) }); /** * Submit Check-in Code * * Submits the generated code to mark the user as attended. */ export const postEventCheckinSubmitMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postEventCheckinSubmit({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; export const getEventInfoQueryKey = (options: Options) => createQueryKey('getEventInfo', options); /** * Get Event Information * * Fetches the name, start time, and end time of an event using its UUID. */ export const getEventInfoOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getEventInfo({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getEventInfoQueryKey(options) }); /** * Join an Event * * Allows an authenticated user to join an event by providing the event ID. The user's role and state are initialized by the service. */ export const postEventJoinMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postEventJoin({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; export const getEventJoinedQueryKey = (options?: Options) => createQueryKey('getEventJoined', options); /** * Get Joined Events * * Fetches a list of events where the authenticated user is a participant. Supports pagination. */ export const getEventJoinedOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getEventJoined({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getEventJoinedQueryKey(options) }); const createInfiniteParams = [0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey, page: K) => { const params = { ...queryKey[0] }; if (page.body) { params.body = { ...queryKey[0].body as any, ...page.body as any }; } if (page.headers) { params.headers = { ...queryKey[0].headers, ...page.headers }; } if (page.path) { params.path = { ...queryKey[0].path as any, ...page.path as any }; } if (page.query) { params.query = { ...queryKey[0].query as any, ...page.query as any }; } return params as unknown as typeof page; }; export const getEventJoinedInfiniteQueryKey = (options?: Options): QueryKey> => createQueryKey('getEventJoined', options, true); /** * Get Joined Events * * Fetches a list of events where the authenticated user is a participant. Supports pagination. */ export const getEventJoinedInfiniteOptions = (options?: Options) => infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( // @ts-ignore { queryFn: async ({ pageParam, queryKey, signal }) => { // @ts-ignore const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { query: { offset: pageParam } }; const params = createInfiniteParams(queryKey, page); const { data } = await getEventJoined({ ...options, ...params, signal, throwOnError: true }); return data; }, queryKey: getEventJoinedInfiniteQueryKey(options) }); export const getEventListQueryKey = (options?: Options) => createQueryKey('getEventList', options); /** * List Events * * Fetches a list of events with support for pagination via limit and offset. Data is retrieved directly from the database for consistency. */ export const getEventListOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getEventList({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getEventListQueryKey(options) }); export const getEventListInfiniteQueryKey = (options?: Options): QueryKey> => createQueryKey('getEventList', options, true); /** * List Events * * Fetches a list of events with support for pagination via limit and offset. Data is retrieved directly from the database for consistency. */ export const getEventListInfiniteOptions = (options?: Options) => infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( // @ts-ignore { queryFn: async ({ pageParam, queryKey, signal }) => { // @ts-ignore const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { query: { offset: pageParam } }; const params = createInfiniteParams(queryKey, page); const { data } = await getEventList({ ...options, ...params, signal, throwOnError: true }); return data; }, queryKey: getEventListInfiniteQueryKey(options) }); /** * Query KYC Status * * Checks the current state of a KYC session and updates local database if approved. */ export const postKycQueryMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postKycQuery({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; /** * Create KYC Session * * Initializes a KYC process (CNRid or Passport) and returns the status or redirect URI. */ export const postKycSessionMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await postKycSession({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; }; export const getUserInfoQueryKey = (options?: Options) => createQueryKey('getUserInfo', options); /** * Get My User Information * * Fetches the complete profile data for the user associated with the provided session/token. */ export const getUserInfoOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserInfo({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getUserInfoQueryKey(options) }); export const getUserInfoByUserIdQueryKey = (options: Options) => createQueryKey('getUserInfoByUserId', options); /** * Get Other User Information * * Fetches the complete profile data for the user associated with the provided session/token. */ export const getUserInfoByUserIdOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserInfoByUserId({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getUserInfoByUserIdQueryKey(options) }); export const getUserListQueryKey = (options: Options) => createQueryKey('getUserList', options); /** * List Users * * Fetches a list of users with support for pagination via limit and offset. Data is sourced from the search engine for high performance. */ export const getUserListOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserList({ ...options, ...queryKey[0], signal, throwOnError: true }); return data; }, queryKey: getUserListQueryKey(options) }); export const getUserListInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getUserList', options, true); /** * List Users * * Fetches a list of users with support for pagination via limit and offset. Data is sourced from the search engine for high performance. */ export const getUserListInfiniteOptions = (options: Options) => infiniteQueryOptions, QueryKey>, string | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( // @ts-ignore { queryFn: async ({ pageParam, queryKey, signal }) => { // @ts-ignore const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { query: { offset: pageParam } }; const params = createInfiniteParams(queryKey, page); const { data } = await getUserList({ ...options, ...params, signal, throwOnError: true }); return data; }, queryKey: getUserListInfiniteQueryKey(options) }); /** * Update User Information * * Updates specific profile fields such as username, nickname, subtitle, avatar (URL), and bio (Base64). * Validation: Username (5-255 chars), Nickname (max 24 chars), Subtitle (max 32 chars). */ export const patchUserUpdateMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (fnOptions) => { const { data } = await patchUserUpdate({ ...options, ...fnOptions, throwOnError: true }); return data; } }; return mutationOptions; };