import {z} from 'zod' export type GetApiApiV1WalletHistoryBuyArgs = {sortType?: ('AMOUNT_ASC' | 'AMOUNT_DESC' | 'ASC' | 'DESC' | 'NONE' | 'PRICE_ASC' | 'PRICE_DESC' | 'UNIT_PRICE_ASC' | 'UNIT_PRICE_DESC') | undefined, pageSize: number, pageNum: number}; export type GetApiApiV1WalletHistoryBuyOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const purchaseHistoryAggregation = z.object({amt: z.number().optional(), price_tot_krw: z.number().optional(), price_tot_usd: z.number().optional()}); export const buyHistory = z.object({amt: z.number().optional(), blockchainTransactionHash: z.string().optional(), cd_nation: z.string().optional(), certificateAgency: z.string().optional(), currency: z.string().optional(), dttm_buy: z.number().int().optional(), id_usr_prod_buy: z.string().optional(), img_thumbnail_prod: z.string().optional(), nm_prod: z.string().optional(), nm_proj: z.string().optional(), nm_proj_dev: z.string().optional(), orderId: z.string().optional(), paymentMethod: z.string().optional(), pgOrderId: z.string().optional(), price_tot_krw: z.number().optional(), price_tot_usd: z.number().optional(), projectId: z.number().int().optional(), project_type: z.enum(["AFFORESTATION_REFORESTATION_AND_REVEGETATION", "AGRICULTURAL_LAND_MANAGEMENT", "AGRICULTURE_FORESTRY_AND_OTHER_LAND_USE", "AVOIDED_CONVERSION_OF_GRASSLANDS_AND_SHRUBLANDS", "CHEMICAL_INDUSTRY", "CLIMATE_CHANGE_ADAPTION", "CONSTRUCTION", "ENERGY", "ENERGY_DEMAND", "ENERGY_DISTRIBUTION", "ENERGY_INDUSTRIES", "FUGITIVE_EMISSIONS_FROM_FUELS__SOLID_OIL_AND_GAS", "IMPROVED_FOREST_MANAGEMENT", "LIVELIHOODS", "LIVESTOCK_ENTERIC_FERMENTATION_AND_MANURE_MANAGEMENT", "MANUFACTURING_INDUSTRIES", "METAL_PRODUCTION", "MINING_MINERAL_ODUCTION", "PLASTIC_WASTE_COLLECTION", "PLASTIC_WASTE_RECYCLING", "REDUCED_EMISSONS_FROM_FORESTATION_AND_DEGRADATION", "TRANSPORT", "UNSPECIFIED", "WASTE_HANDLING_AND_DISPOSAL", "WATER_ACCESS_AND_SANITATIO", "WETLAND_REWETTING_AND_CONSVATION"]).optional(), status_act: z.enum(["CANCELED", "FAIL", "PENDING", "SUCCESS"]).optional()}); export const winclAggregationResponseBuyHistoryPurchaseHistoryAggregation = z.object({aggregation: purchaseHistoryAggregation.optional(), code: z.string().optional(), currentPageNum: z.number().int().optional(), items: z.array(buyHistory).optional(), message: z.string().optional(), pageSize: z.number().int().optional(), sortType: z.enum(["AMOUNT_ASC", "AMOUNT_DESC", "ASC", "DESC", "NONE", "PRICE_ASC", "PRICE_DESC", "UNIT_PRICE_ASC", "UNIT_PRICE_DESC"]).optional(), totalCount: z.number().int().optional(), totalPages: z.number().int().optional()}); 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 /api/v1/wallet/history/buy */ export const getApiApiV1WalletHistoryBuy = async (args: GetApiApiV1WalletHistoryBuyArgs, options?: GetApiApiV1WalletHistoryBuyOptions) => { const {baseUrl = "https://api.wincl.io:443", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sortType != null) query.append("sortType", String(args.sortType)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageNum != null) query.append("pageNum", String(args.pageNum)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/wallet/history/buy${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(winclAggregationResponseBuyHistoryPurchaseHistoryAggregation, await res.json()) };