import {z} from 'zod' export type GetApiApiV1WalletGiftSentArgs = {pageSize: number, pageNum: number}; export type GetApiApiV1WalletGiftSentOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const sentGiftHistoryAggregation = z.object({currency: z.enum(["KRW", "USD"]).optional(), totalGiftPrice: z.number().optional(), totalSentAmount: z.number().optional()}); export const sentGift = z.object({amt: z.number().optional(), blockchainTransactionHash: z.string().optional(), blockchainTransactionStatus: z.string().optional(), cancelTransactionHash: z.string().optional(), dttm_deadline: z.number().int().optional(), dttm_receive: z.number().int().optional(), dttm_send: z.number().int().optional(), email: z.string().optional(), id_gift: z.string().optional(), id_login_send: z.string().optional(), id_prod: z.string().optional(), id_usr_send: z.string().optional(), nm_prod: z.string().optional(), phone: z.string().optional(), projectId: z.number().int().optional(), status: z.enum(["AUTO_CANCEL", "PENDING", "RECEIVE", "SND_CANCEL"]).optional(), tp_transfer: z.enum(["COUPON", "EMAIL", "PHONE"]).optional()}); export const winclAggregationResponseSentGiftSentGiftHistoryAggregation = z.object({aggregation: sentGiftHistoryAggregation.optional(), code: z.string().optional(), currentPageNum: z.number().int().optional(), items: z.array(sentGift).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/sent */ export const getApiApiV1WalletGiftSent = async (args: GetApiApiV1WalletGiftSentArgs, options?: GetApiApiV1WalletGiftSentOptions) => { 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/sent${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(winclAggregationResponseSentGiftSentGiftHistoryAggregation, await res.json()) };