import {z} from 'zod' export type ItemOriginModel = 'brute' | 'phishing' | 'stealer' | 'autoreg' | 'personal' | 'resale' | 'dummy' | 'self_registration' | 'retrieve_via_support'; export type YesNoNoMatterScheme = 'yes' | 'no' | 'nomatter'; export type GetApiEaArgs = {after?: string | undefined, pmin?: number | undefined, pmax?: number | undefined, title?: string | 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, 'tag_id[]'?: Array | undefined, 'not_tag_id[]'?: Array | undefined, 'public_tag_id[]'?: Array | undefined, 'not_public_tag_id[]'?: Array | undefined, 'origin[]'?: ('brute' | 'phishing' | 'stealer' | 'autoreg' | 'personal' | 'resale' | 'dummy' | 'self_registration' | 'retrieve_via_support') | undefined, 'not_origin[]'?: Array | undefined, user_id?: number | undefined, nsb?: boolean | undefined, sb?: boolean | undefined, nsb_by_me?: boolean | undefined, sb_by_me?: boolean | undefined, currency?: ('rub' | 'uah' | 'kzt' | 'byn' | 'usd' | 'eur' | 'gbp' | 'cny' | 'try' | 'jpy' | 'brl') | undefined, email_login_data?: boolean | undefined, 'email_provider[]'?: (Array<'other' | 'rambler' | 'outlook' | 'firstmail' | 'notletters' | 'mail_ru'>) | undefined, 'not_email_provider[]'?: ('other' | 'rambler' | 'outlook' | 'firstmail' | 'notletters' | 'mail_ru') | undefined, parse_same_item_ids?: boolean | undefined, 'email_type[]'?: (Array<'autoreg' | 'native' | 'no'>) | undefined, item_domain?: string | undefined, 'game[]'?: Array | undefined, 'country[]'?: Array | undefined, 'not_country[]'?: Array | undefined, gmin?: number | undefined, gmax?: number | undefined, al_rank_min?: (0 | 250 | 500 | 750 | 1000 | 1500 | 2000 | 2500 | 3000 | 3600 | 4200 | 4800 | 5400 | 6100 | 6800 | 7500 | 8200 | 9000 | 9800 | 10600 | 11400 | 12300 | 13200 | 14100 | 15000) | undefined, al_rank_max?: (249 | 499 | 749 | 999 | 1499 | 1999 | 2499 | 2999 | 3599 | 4199 | 4799 | 5399 | 6099 | 6799 | 7499 | 8199 | 8999 | 9799 | 10599 | 11399 | 12299 | 13199 | 14099 | 14999 | 500000) | undefined, al_level_min?: number | undefined, al_level_max?: number | undefined, has_ban?: YesNoNoMatterScheme | undefined, xbox_connected?: YesNoNoMatterScheme | undefined, steam_connected?: YesNoNoMatterScheme | undefined, psn_connected?: YesNoNoMatterScheme | undefined, subscription?: ('EA Play' | 'EA Play Pro') | undefined, subscription_length?: number | undefined, subscription_period?: ('day' | 'month' | 'year') | undefined, hours_played?: {[key: string]: number} | undefined, hours_played_max?: {[key: string]: number} | undefined, transactions?: YesNoNoMatterScheme | undefined}; export type GetApiEaOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; 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 getApiEaResponse = z.object({items: z.array(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().nullable(), 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.object({ask_date: z.number().int(), ask_item_id: z.number().int(), ask_user_id: z.number().int(), auto_buy: z.boolean(), auto_buy_max_price: z.number().int(), balance_id: z.string(), discount_accepted: z.boolean(), discount_price: z.number().int(), message: z.string()}).nullable(), ea_item_id: z.number().int(), ea_id: z.number().int(), ea_country: z.string(), ea_games: z.object({"apex-legends": z.object({game_id: z.string(), title: z.string(), last_activity: z.number().int(), total_played: z.number().int(), abbr: z.string(), img: z.string()})}), ea_game_count: z.number().int(), ea_last_activity: z.number().int(), ea_al_level: z.number().int(), ea_al_rank_score: z.number().int(), ea_subscription: z.string(), ea_subscription_end_date: z.number().int(), ea_username: z.string(), ea_xbox_connected: z.number().int(), ea_steam_connected: z.number().int(), ea_psn_connected: z.number().int(), ea_bans: z.array(z.object({type: z.string(), date: z.number().int(), name: z.string()})), ea_has_ban: z.number().int(), ea_transactions: z.string(), 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.number().int().nullable(), active: z.number().int().nullable(), cancelled: z.number().int().nullable(), remainingTime: z.number().int().nullable()}), 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.unknown(), isPersonalAccount: z.boolean(), canBuyItem: z.boolean(), price_currency: z.string(), priceWithSellerFeeLabel: z.string(), canValidateAccount: z.boolean(), canChangeOwner: z.boolean(), canResellItem: z.boolean(), relevantGameCount: z.number().int(), totalGameCount: z.number().int(), paidGameCount: z.number().int(), freeGameCount: z.number().int(), eaTransactions: z.array(z.unknown()), canViewAccountLink: z.boolean(), accountLinks: z.array(z.object({link: z.string(), text: z.string(), iconClass: z.string()})), accountLink: z.string(), imagePreviewLinks: z.array(z.unknown()), 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.record(z.string(), z.object({tag_id: z.number().int(), title: z.string(), isDefault: z.boolean(), forOwnedAccountsOnly: z.boolean(), bc: z.string()}))).nullable(), public_tag: z.object({background_color: z.string(), tag_id: z.number().int(), title: z.string()}).nullable(), note_text: z.string().nullable(), 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().nullable()}), ea_al_rank: z.string()})), totalItems: z.number().int(), totalItemsPrice: z.unknown(), hasNextPage: z.boolean(), nextCursor: z.string(), perPage: z.number().int(), page: z.number().int(), wasCached: z.boolean(), cacheTTL: z.number().int(), lastModified: z.number().int(), serverTime: z.number().int(), searchUrl: z.string(), search: z.string(), stickyItems: z.array(z.unknown()), 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(), 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 }; /** * EA (Origin) * * GET /ea */ export const getApiEa = async (args: GetApiEaArgs, options?: GetApiEaOptions) => { 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.after != null) query.append("after", String(args.after)) if (args.pmin != null) query.append("pmin", String(args.pmin)) if (args.pmax != null) query.append("pmax", String(args.pmax)) if (args.title != null) query.append("title", String(args.title)) if (args.order_by != null) query.append("order_by", String(args.order_by)) for (const item of args['tag_id[]'] ?? []) query.append("tag_id[]", String(item)) for (const item of args['not_tag_id[]'] ?? []) query.append("not_tag_id[]", String(item)) for (const item of args['public_tag_id[]'] ?? []) query.append("public_tag_id[]", String(item)) for (const item of args['not_public_tag_id[]'] ?? []) query.append("not_public_tag_id[]", String(item)) 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.user_id != null) query.append("user_id", String(args.user_id)) if (args.nsb != null) query.append("nsb", String(args.nsb)) if (args.sb != null) query.append("sb", String(args.sb)) if (args.nsb_by_me != null) query.append("nsb_by_me", String(args.nsb_by_me)) if (args.sb_by_me != null) query.append("sb_by_me", String(args.sb_by_me)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.email_login_data != null) query.append("email_login_data", String(args.email_login_data)) for (const item of args['email_provider[]'] ?? []) query.append("email_provider[]", String(item)) if (args['not_email_provider[]'] != null) query.append("not_email_provider[]", String(args['not_email_provider[]'])) if (args.parse_same_item_ids != null) query.append("parse_same_item_ids", String(args.parse_same_item_ids)) for (const item of args['email_type[]'] ?? []) query.append("email_type[]", String(item)) if (args.item_domain != null) query.append("item_domain", String(args.item_domain)) for (const item of args['game[]'] ?? []) query.append("game[]", String(item)) for (const item of args['country[]'] ?? []) query.append("country[]", String(item)) for (const item of args['not_country[]'] ?? []) query.append("not_country[]", String(item)) if (args.gmin != null) query.append("gmin", String(args.gmin)) if (args.gmax != null) query.append("gmax", String(args.gmax)) if (args.al_rank_min != null) query.append("al_rank_min", String(args.al_rank_min)) if (args.al_rank_max != null) query.append("al_rank_max", String(args.al_rank_max)) if (args.al_level_min != null) query.append("al_level_min", String(args.al_level_min)) if (args.al_level_max != null) query.append("al_level_max", String(args.al_level_max)) if (args.has_ban != null) query.append("has_ban", String(args.has_ban)) if (args.xbox_connected != null) query.append("xbox_connected", String(args.xbox_connected)) if (args.steam_connected != null) query.append("steam_connected", String(args.steam_connected)) if (args.psn_connected != null) query.append("psn_connected", String(args.psn_connected)) if (args.subscription != null) query.append("subscription", String(args.subscription)) if (args.subscription_length != null) query.append("subscription_length", String(args.subscription_length)) if (args.subscription_period != null) query.append("subscription_period", String(args.subscription_period)) if (args.hours_played != null) query.append("hours_played", JSON.stringify(args.hours_played)) if (args.hours_played_max != null) query.append("hours_played_max", JSON.stringify(args.hours_played_max)) if (args.transactions != null) query.append("transactions", String(args.transactions)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/ea${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(getApiEaResponse, await res.json()) };