import {z} from 'zod' export type GetApiPromoOffersLogsArgs = {limit?: number | undefined, offset?: number | undefined, user_id?: (number | null) | undefined, offer_id?: (number | null) | undefined, action?: (string | null) | undefined, source?: (string | null) | undefined}; export type GetApiPromoOffersLogsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const appWebapiSchemasPromoOffersPromoOfferUserInfo = z.object({id: z.number().int(), telegram_id: z.number().int().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 appWebapiSchemasPromoOffersPromoOfferLogResponse = 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: appWebapiSchemasPromoOffersPromoOfferUserInfo.nullable().optional(), offer: promoOfferLogOfferInfo.nullable().optional()}); export const appWebapiSchemasPromoOffersPromoOfferLogListResponse = z.object({items: z.array(appWebapiSchemasPromoOffersPromoOfferLogResponse), 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 Promo Offer Logs * * GET /promo-offers/logs */ export const getApiPromoOffersLogs = async (args: GetApiPromoOffersLogsArgs, options: GetApiPromoOffersLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = 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.offer_id != null) query.append("offer_id", String(args.offer_id)) if (args.action != null) query.append("action", String(args.action)) if (args.source != null) query.append("source", String(args.source)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/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(appWebapiSchemasPromoOffersPromoOfferLogListResponse, await res.json()) };