export type CreateBadgeAttributionDto = {badgeId: string, metadata?: Record | undefined, jwt: string, autoClaim?: boolean | undefined}; export type CreateApiLauncherIdUpsertAttributionArgs = {'x-api-key': string, id: string, conditionKey: string, condition: string, body: CreateBadgeAttributionDto}; export type CreateApiLauncherIdUpsertAttributionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create or update a badge attribution * * POST /launcher/{id}/upsert-attribution */ export const createApiLauncherIdUpsertAttribution = async (args: CreateApiLauncherIdUpsertAttributionArgs, options?: CreateApiLauncherIdUpsertAttributionOptions) => { const {baseUrl = "https://api.openpage.fun/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (args.conditionKey != null) query.append("conditionKey", String(args.conditionKey)) if (args.condition != null) query.append("condition", String(args.condition)) const url = `${baseUrl.replace(/\/+$/, '')}/launcher/${encodeURIComponent(String(args.id))}/upsert-attribution${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 };