import {z} from 'zod' export type CategoryIDModel = 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 28 | 30 | 31; export type ItemOriginModel = 'brute' | 'phishing' | 'stealer' | 'autoreg' | 'personal' | 'resale' | 'dummy' | 'self_registration' | 'retrieve_via_support'; export type GetApiUserItemsArgs = {user_id?: number | undefined, category_id?: CategoryIDModel | undefined, after?: string | undefined, show?: ('stickied' | 'discount_request' | 'in_buyers_favorites' | 'active' | 'paid' | 'closed' | 'deleted' | 'awaiting' | 'pre_active' | 'pre_upload' | 'pending_deletion' | 'closed_inactive' | 'auto_bump') | undefined, delete_reason?: string | undefined, title?: string | undefined, pmin?: number | undefined, pmax?: number | undefined, login?: string | undefined, 'origin[]'?: ('brute' | 'phishing' | 'stealer' | 'autoreg' | 'personal' | 'resale' | 'dummy' | 'self_registration' | 'retrieve_via_support') | undefined, 'not_origin[]'?: Array | undefined, order_by?: ('price_to_up' | 'price_to_down' | 'pdate_to_down' | 'pdate_to_up' | 'pdate_to_down_upload' | 'pdate_to_up_upload' | 'edate_to_up' | 'edate_to_down' | 'ddate_to_up' | 'ddate_to_down' | 'auto_buy_diff_to_up' | 'auto_buy_diff_to_down') | undefined, sb?: boolean | undefined, sb_by_me?: boolean | undefined, nsb?: boolean | undefined, nsb_by_me?: boolean | undefined, username?: string | undefined, published_startDate?: string | undefined, published_endDate?: string | undefined, filter_by_published_date?: boolean | undefined, paid_startDate?: string | undefined, paid_endDate?: string | undefined, filter_by_buyer_operation_date?: boolean | undefined, delete_startDate?: string | undefined, delete_endDate?: string | undefined, filter_by_delete_date?: boolean | undefined}; export type GetApiUserItemsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const itemModel = z.object({item_id: z.number().int(), item_state: z.string(), category_id: z.number().int(), published_date: z.number().int(), title: z.string(), description: z.string(), price: z.number().int(), update_stat_date: z.number().int(), refreshed_date: z.number().int(), edit_date: z.number().int(), pending_deletion_date: z.number().int(), view_count: z.number().int(), is_sticky: z.number().int(), item_origin: z.string(), extended_guarantee: z.number().int(), nsb: z.number().int(), allow_ask_discount: z.number().int(), title_en: z.string(), description_en: z.string(), email_type: z.string(), email_provider: z.string(), item_domain: z.string(), resale_item_origin: z.string(), auto_bump_period: z.number().int(), guarantee_duration: z.number().int(), rub_price: z.number().int(), discount: z.boolean(), feedback_data: z.string(), max_discount_percent: z.number().int(), priceWithSellerFee: z.number(), category: z.object({category_id: z.number().int(), category_title: z.string(), category_name: z.string(), category_url: z.string()}), guarantee: z.object({duration: z.number().int(), class: z.string(), durationPhrase: z.string(), endDate: z.unknown(), active: z.unknown(), cancelled: z.unknown(), remainingTime: z.unknown()}), canViewLoginData: z.boolean(), canViewTempEmail: z.boolean(), canUpdateItemStats: z.boolean(), canReportItem: z.boolean(), canViewItemViews: z.boolean(), canManagePublicTag: z.boolean(), canViewEmailLoginData: z.boolean(), copyFormatData: z.object({title_link: z.string()}), showGetEmailCodeButton: z.boolean(), canOpenItem: z.boolean(), canCloseItem: z.boolean(), canEditItem: z.boolean(), canDeleteItem: z.boolean(), canStickItem: z.boolean(), canUnstickItem: z.boolean(), canBumpItem: z.boolean(), canNotBumpItemReason: z.string(), canAutoBump: z.boolean(), buyer: z.object({user_id: z.number().int(), operation_date: z.number().int(), visitorIsBuyer: z.boolean()}), isPersonalAccount: z.boolean(), canBuyItem: z.boolean(), price_currency: z.string(), priceWithSellerFeeLabel: z.string(), canValidateAccount: z.boolean(), canResellItem: z.boolean(), canViewAccountLink: z.boolean().optional(), accountLinks: z.array(z.object({link: z.string(), text: z.string(), iconClass: z.string()})), accountLink: z.string(), imagePreviewLinks: z.object({download: z.object({games: z.string()})}), emailLoginUrl: z.string(), canChangePassword: z.boolean(), canChangeEmailPassword: z.boolean(), uniqueKeyExists: z.boolean(), itemOriginPhrase: z.string(), sold_items_category_count: z.number().int(), restore_items_category_count: z.number().int(), tags: z.array(z.unknown()), public_tag: z.object({background_color: z.string(), tag_id: z.number().int(), title: z.string()}), note_text: z.string(), descriptionHtml: z.string(), descriptionEnHtml: z.string(), descriptionPlain: z.string(), descriptionEnPlain: z.string(), seller: z.object({user_id: z.number().int(), sold_items_count: z.number().int(), active_items_count: z.number().int(), restore_data: z.string(), username: z.string(), avatar_date: z.number().int(), is_banned: z.number().int(), display_style_group_id: z.number().int(), restore_percents: z.number().int()})}); export const respSystemInfo = z.object({rate_limit: z.object({limit: z.number().int(), remaining: z.number().int(), reset: z.number().int(), bucket: z.string().optional()}), visitor_id: z.number().int(), time: z.number().int(), log_id: z.number().int()}); export const getApiUserItemsResponse = z.object({items: z.array(itemModel), totalItems: z.number().int(), totalItemsPrice: z.number().int(), hasNextPage: z.boolean(), perPage: z.number().int(), page: z.number().int(), wasCached: z.boolean(), cacheTTL: z.number().int(), lastModified: z.number().int(), serverTime: z.number().int(), totalItemsPriceWithSellerFee: z.number(), searchUrl: z.string(), search: z.string(), stickyItems: z.array(z.unknown()), user: z.object({user_id: z.number().int(), username: z.string(), display_style_group_id: z.number().int(), avatar_date: z.number().int(), is_banned: z.boolean(), uniq_username_css: z.string()}), publishedPeriodLabelPhrase: z.string(), filterDatesDefault: z.boolean(), published_startDate: z.string(), published_endDate: z.string(), filter_by_published_date: z.boolean(), published_period_label: z.string(), paidPeriodLabelPhrase: z.string(), paid_startDate: z.string(), paid_endDate: z.string(), filter_by_buyer_operation_date: z.boolean(), paid_period_label: z.string(), deletePeriodLabelPhrase: z.string(), delete_startDate: z.string(), delete_endDate: z.string(), filter_by_delete_date: z.boolean(), delete_period_label: z.string(), system_info: respSystemInfo}); 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 All User Accounts * * GET /user/items */ export const getApiUserItems = async (args: GetApiUserItemsArgs, options?: GetApiUserItemsOptions) => { const {baseUrl = "https://api.lzt.market", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.category_id != null) query.append("category_id", String(args.category_id)) if (args.after != null) query.append("after", String(args.after)) if (args.show != null) query.append("show", String(args.show)) if (args.delete_reason != null) query.append("delete_reason", String(args.delete_reason)) if (args.title != null) query.append("title", String(args.title)) if (args.pmin != null) query.append("pmin", String(args.pmin)) if (args.pmax != null) query.append("pmax", String(args.pmax)) if (args.login != null) query.append("login", String(args.login)) if (args['origin[]'] != null) query.append("origin[]", String(args['origin[]'])) for (const item of args['not_origin[]'] ?? []) query.append("not_origin[]", String(item)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.sb != null) query.append("sb", String(args.sb)) if (args.sb_by_me != null) query.append("sb_by_me", String(args.sb_by_me)) if (args.nsb != null) query.append("nsb", String(args.nsb)) if (args.nsb_by_me != null) query.append("nsb_by_me", String(args.nsb_by_me)) if (args.username != null) query.append("username", String(args.username)) if (args.published_startDate != null) query.append("published_startDate", String(args.published_startDate)) if (args.published_endDate != null) query.append("published_endDate", String(args.published_endDate)) if (args.filter_by_published_date != null) query.append("filter_by_published_date", String(args.filter_by_published_date)) if (args.paid_startDate != null) query.append("paid_startDate", String(args.paid_startDate)) if (args.paid_endDate != null) query.append("paid_endDate", String(args.paid_endDate)) if (args.filter_by_buyer_operation_date != null) query.append("filter_by_buyer_operation_date", String(args.filter_by_buyer_operation_date)) if (args.delete_startDate != null) query.append("delete_startDate", String(args.delete_startDate)) if (args.delete_endDate != null) query.append("delete_endDate", String(args.delete_endDate)) if (args.filter_by_delete_date != null) query.append("filter_by_delete_date", String(args.filter_by_delete_date)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/user/items${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(getApiUserItemsResponse, await res.json()) };