import {z} from 'zod' export type GetApiApiV1WalletGiftReceivedArgs = {pageSize: number, pageNum: number}; export type GetApiApiV1WalletGiftReceivedOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const receivedGiftHistoryAggregation = z.object({currency: z.enum(["KRW", "USD"]).optional(), totalGiftPrice: z.number().optional(), totalReceivedAmount: z.number().optional()}); export const receivedGift = z.object({amt: z.number().optional(), blockchainTransactionHash: z.string().optional(), blockchainTransactionStatus: z.string().optional(), dttm_receive: z.number().int().optional(), dttm_send: z.number().int().optional(), email_send: z.string().optional(), id_gift: z.string().optional(), id_login_send: z.string().optional(), id_prod: z.string().optional(), id_usr_prod_rcv: z.string().optional(), id_usr_send: z.string().optional(), nm_prod: z.string().optional(), projectId: z.string().optional(), status: z.enum(["AUTO_CANCEL", "PENDING", "RECEIVE", "SND_CANCEL"]).optional(), tp_transfer: z.enum(["COUPON", "EMAIL", "PHONE"]).optional()}); export const winclAggregationResponseReceivedGiftReceivedGiftHistoryAggregation = z.object({aggregation: receivedGiftHistoryAggregation.optional(), code: z.string().optional(), currentPageNum: z.number().int().optional(), items: z.array(receivedGift).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/gift/received */ export const getApiApiV1WalletGiftReceived = async (args: GetApiApiV1WalletGiftReceivedArgs, options?: GetApiApiV1WalletGiftReceivedOptions) => { 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.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/gift/received${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(winclAggregationResponseReceivedGiftReceivedGiftHistoryAggregation, await res.json()) };