export type GetApiCommunityIdBadgeBadgeIdCodeArgs = {id: string, badgeId: string, seed?: string | undefined, expiresIn?: number | undefined, generateQR: boolean}; export type GetApiCommunityIdBadgeBadgeIdCodeOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Generate badge attribution code * * GET /community/{id}/badge/{badgeId}/code */ export const getApiCommunityIdBadgeBadgeIdCode = async (args: GetApiCommunityIdBadgeBadgeIdCodeArgs, options?: GetApiCommunityIdBadgeBadgeIdCodeOptions) => { const {baseUrl = "https://api.openpage.fun/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.seed != null) query.append("seed", String(args.seed)) if (args.expiresIn != null) query.append("expiresIn", String(args.expiresIn)) if (args.generateQR != null) query.append("generateQR", String(args.generateQR)) if (apiKey !== undefined) headers.set("X-Api-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/community/${encodeURIComponent(String(args.id))}/badge/${encodeURIComponent(String(args.badgeId))}/code${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 undefined };