export type BadgeTagDto = {id: string, name: string}; export type BadgeAuthorDto = {name: string, uri: string}; export type CreateBadgeDto = {status?: ('draft' | 'under_review' | 'approved' | 'rejected' | 'live') | undefined, title: string, image: string, type: 'achievement' | 'attendance', description: string, chainId?: string | undefined, contract?: string | undefined, claimEndDate: string, maxClaims: number, tags: Array, author: BadgeAuthorDto}; export type CreateApiCommunityIdBadgeArgs = {id: string, body: CreateBadgeDto}; export type CreateApiCommunityIdBadgeOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create badge * * POST /community/{id}/badge */ export const createApiCommunityIdBadge = async (args: CreateApiCommunityIdBadgeArgs, options?: CreateApiCommunityIdBadgeOptions) => { const {baseUrl = "https://api.openpage.fun/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set("X-Api-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/community/${encodeURIComponent(String(args.id))}/badge${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };