import {z} from 'zod' export type FeedbackProposal = {kind: 'new_term', lang?: string | undefined, payload: {term: string, definition?: string | undefined, translation?: {lang: string, prose: string} | undefined}, reason?: string | undefined} | {kind: 'redundant', termId: string, hash?: string | undefined, payload: {with: Array}, reason?: string | undefined} | {kind: 'split', termId: string, hash?: string | undefined, payload: {into: Array<{term: string, definition?: string | undefined}>}, reason?: string | undefined} | {kind: 'definition', termId: string, hash: string, payload: {definition: string}, reason?: string | undefined} | {kind: 'note', termId: string, hash: string, payload: {note: string | null}, reason?: string | undefined} | {kind: 'references', termId: string, hash: string, payload: {add?: Array<{label: string, url: string}> | undefined, remove?: Array | undefined}, reason?: string | undefined} | {kind: 'avoid', termId: string, hash: string, payload: {add?: Array | undefined, remove?: Array | undefined}, reason?: string | undefined} | {kind: 'alias', termId: string, hash: string, payload: {add?: (Array<{term: string, status?: ('preferred' | 'accepted' | 'deprecated') | undefined}>) | undefined, remove?: Array | undefined}, reason?: string | undefined} | {kind: 'casing', termId: string, hash: string, payload: {casing: 'standard' | 'proper' | 'uppercase' | 'fixed'}, reason?: string | undefined} | {kind: 'category', termId: string, hash: string, payload: {category: string}, reason?: string | undefined} | {kind: 'script_rule', termId: string, hash: string, payload: {script_rule: 'translate' | 'calque' | 'transliterate' | 'keep_latin' | 'always_latin' | 'transliterate_with_translation'}, reason?: string | undefined}; export type CreateApiApiV1FeedbackProposalsArgs = {body: FeedbackProposal}; export type CreateApiApiV1FeedbackProposalsOptions = {baseUrl?: string | undefined, cookieAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const feedbackProposalResponse = z.object({id: z.string()}); 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 }; /** * Propose a new term, flag a term as redundant or in need of a split, or suggest a change to a term's English metadata * * POST /api/v1/feedback/proposals */ export const createApiApiV1FeedbackProposals = async (args: CreateApiApiV1FeedbackProposalsArgs, options?: CreateApiApiV1FeedbackProposalsOptions) => { const {baseUrl = "https://glossary.ethereum.org", fetch: fetchFn = fetch, cookieAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (cookieAuth !== undefined) cookies.push("ethglossary-session=" + encodeURIComponent(cookieAuth)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/feedback/proposals${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 validateResponse(feedbackProposalResponse, await res.json()) };