import {z} from 'zod' export type GetApiApiV1WalletCertShareArgs = {loginId: string, projectId: number}; export type GetApiApiV1WalletCertShareOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const creditOffset = z.object({amt_offset: z.number().optional(), blockchainTransactionHash: z.string().optional(), blockchainTransactionStatus: z.string().optional(), dttm_offset: z.number().int().optional(), id_credit: z.string().optional()}); export const certSerial = z.object({cert_serial_end: z.string().optional(), cert_serial_start: z.string().optional(), ton: z.number().optional()}); export const certDetail = z.object({amt: z.number().optional(), cd_nation: z.string().optional(), certificateVcCid: z.string().optional(), corrs_adj: z.number().optional(), credit_offset_history: z.array(creditOffset).optional(), credit_serial_prefix: z.string().optional(), currency: z.string().optional(), first_offset_epoch: z.number().int().optional(), id_login: z.string().optional(), id_proj: z.number().int().optional(), img_thumbnail_proj: z.string().optional(), last_offset_epoch: z.number().int().optional(), nationEnglishName: z.string().optional(), nationKoreanName: z.string().optional(), nickname: z.string().optional(), nm_cert_agc: z.string().optional(), nm_proj: z.string().optional(), nm_proj_dev: z.string().optional(), productName: z.string().optional(), projectRegistrationTimestamp: z.number().int().optional(), projectTopicId: z.string().optional(), project_effect: z.array(z.enum(["AFFORDABLE_AND_CLEAN_ENERGY", "CLEAN_WATER_AND_SANITATION", "CLIMATE_ACTION", "DECENT_WORK_AND_ECONOMIC_GROWTH", "GENDER_EQUALITY", "GOOD_HEALTH_AND_WELLBEING", "INDUSTRY_INNOVATION_AND_INFRASTRUCTURE", "LIFE_BELLOW_WATER", "LIFE_ON_LAND", "NO_POVERTY", "PARTNERSHIPS_FOR_THE_GOALS", "PEACE_JUSTICE_AND_STRONG_INSTITUTIONS", "QUALITY_EDUCATION", "REDUCED_INEQUALITIES", "RESPONSIBLE_CONSUMPTION_AND_PRODUCTION", "SUSTAINABLE_CITIES_AND_COMMUNITIES", "ZERO_HUNGER"])).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(), serial_list: z.array(certSerial).optional()}); export const winclResponseDataCertDetail = z.object({code: z.string().optional(), data: certDetail.optional(), message: z.string().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/cert/share */ export const getApiApiV1WalletCertShare = async (args: GetApiApiV1WalletCertShareArgs, options?: GetApiApiV1WalletCertShareOptions) => { 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.loginId != null) query.append("loginId", String(args.loginId)) if (args.projectId != null) query.append("projectId", String(args.projectId)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/wallet/cert/share${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(winclResponseDataCertDetail, await res.json()) };