import {z} from 'zod' export type BusinessExpand = 'user'; export type SearchFindBusinessDto = {paymentPeriod?: string | undefined, userId?: string | undefined}; export type SortMode = 'asc' | 'desc'; export type SortFindBusinessDto = {userId?: SortMode | undefined, createdAt?: ('asc' | 'desc') | undefined}; export type GetApiV1AdminPayoutBusinessArgs = {_expand?: BusinessExpand | undefined, expand?: Array | undefined, search?: SearchFindBusinessDto | undefined, sort?: SortFindBusinessDto | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1AdminPayoutBusinessOptions = {baseUrl: string, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const creator = z.object({avatar: z.string(), id: z.string(), partnerName: z.string(), avatarAssetId: z.string(), profileColor: z.string(), userName: z.string(), createdAt: z.string(), updatedAt: z.string()}); export const walletLeague = z.object({name: z.string(), leaderboardId: z.string()}); export const dailySetCount = z.object({totalCompleted: z.number(), totalWins: z.number(), totalLosses: z.number(), totalTies: z.number()}); export const walletResponse = z.object({id: z.string(), coins: z.number(), pendingCoins: z.number(), whiteTickets: z.number(), blackTickets: z.number(), grayTickets: z.number(), points: z.number(), createdAt: z.string(), updatedAt: z.string(), version: z.number(), canCollectFreeGift: z.boolean(), gamesDeclared: z.number(), gamesCorrectAnswers: z.number(), achievements: z.array(z.string()), currentLeague: z.enum(["level1", "level2", "level3", "level4"]), gamePlaysSinceDemotion: z.number(), lifetimeGamesPlayed: z.number(), emailVerified: z.boolean(), leagues: z.array(walletLeague).optional(), referralCount: z.number(), dailySetCounts: dailySetCount}); export const expandedBusiness = z.object({profile: creator, balance: walletResponse, id: z.string(), userId: z.string(), coins: z.number(), paymentPeriod: z.string(), createdAt: z.string()}); export const listExpandedBusinessEntity = z.object({items: z.array(expandedBusiness), total: z.number()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * GET /v1/admin/payout/business */ export const getApiV1AdminPayoutBusiness = async (args: GetApiV1AdminPayoutBusinessArgs, options: GetApiV1AdminPayoutBusinessOptions) => { const {baseUrl, fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args._expand != null) query.append("_expand", String(args._expand)) for (const item of args.expand ?? []) query.append("expand", String(item)) if (args.search != null) query.append("search", JSON.stringify(args.search)) if (args.sort != null) query.append("sort", JSON.stringify(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/payout/business${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listExpandedBusinessEntity, await res.json()) };