export type ApiCommentCreateRequest = {namespace?: string | undefined, key: string, language: string, content: string}; export type CreateApiApiV1CommentsArgs = {'X-SimpleLocalize-Token': string, Authorization: string, body: ApiCommentCreateRequest}; export type CreateApiApiV1CommentsOptions = {baseUrl?: string | undefined, ProjectAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create comment * * POST /api/v1/comments * * Also accepts auth: Personal Access Token */ export const createApiApiV1Comments = async (args: CreateApiApiV1CommentsArgs, options?: CreateApiApiV1CommentsOptions) => { const {baseUrl = "https://api.simplelocalize.io", fetch: fetchFn = fetch, ProjectAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-SimpleLocalize-Token'] != null) headers.set("X-SimpleLocalize-Token", String(args['X-SimpleLocalize-Token'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (ProjectAPIKey !== undefined) headers.set("X-SimpleLocalize-Token", ProjectAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/comments${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 };