import {z} from 'zod' export type GetApiCabinetAdminPromoOffersLogsArgs = {limit?: number | undefined, offset?: number | undefined, user_id?: (number | null) | undefined, action?: (string | null) | undefined}; export type GetApiCabinetAdminPromoOffersLogsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const appCabinetRoutesAdminPromoOffersPromoOfferUserInfo = z.object({id: z.number().int(), telegram_id: z.number().int().nullable().optional(), email: z.string().nullable().optional(), username: z.string().nullable().optional(), first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), full_name: z.string().nullable().optional()}); export const promoOfferLogOfferInfo = z.object({id: z.number().int(), notification_type: z.string().nullable().optional(), discount_percent: z.number().int().nullable().optional(), bonus_amount_kopeks: z.number().int().nullable().optional(), effect_type: z.string().nullable().optional(), expires_at: z.string().nullable().optional(), claimed_at: z.string().nullable().optional(), is_active: z.boolean().nullable().optional()}); export const appCabinetRoutesAdminPromoOffersPromoOfferLogResponse = z.object({id: z.number().int(), user_id: z.number().int().nullable().optional(), offer_id: z.number().int().nullable().optional(), action: z.string(), source: z.string().nullable().optional(), percent: z.number().int().nullable().optional(), effect_type: z.string().nullable().optional(), details: z.record(z.string(), z.unknown()).optional(), created_at: z.string(), user: appCabinetRoutesAdminPromoOffersPromoOfferUserInfo.nullable().optional(), offer: promoOfferLogOfferInfo.nullable().optional()}); export const appCabinetRoutesAdminPromoOffersPromoOfferLogListResponse = z.object({items: z.array(appCabinetRoutesAdminPromoOffersPromoOfferLogResponse), total: z.number().int(), limit: z.number().int(), offset: z.number().int()}); 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 Logs * * GET /cabinet/admin/promo-offers/logs */ export const getApiCabinetAdminPromoOffersLogs = async (args: GetApiCabinetAdminPromoOffersLogsArgs, options: GetApiCabinetAdminPromoOffersLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.action != null) query.append("action", String(args.action)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/promo-offers/logs${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(appCabinetRoutesAdminPromoOffersPromoOfferLogListResponse, await res.json()) };