import {z} from 'zod' export type GetApiV1PronunciationDictionariesArgs = {cursor?: (string | null) | undefined, page_size?: number | undefined, sort?: ('creation_time_unix' | 'name' | null) | undefined, sort_direction?: (string | null) | undefined, include_archived?: boolean | undefined, 'xi-api-key'?: (string | null) | undefined}; export type GetApiV1PronunciationDictionariesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getPronunciationDictionaryMetadataResponseModel = z.object({id: z.string(), latest_version_id: z.string(), latest_version_rules_num: z.number().int(), name: z.string(), permission_on_resource: z.enum(["admin", "editor", "commenter", "viewer"]).nullable(), created_by: z.string(), creation_time_unix: z.number().int(), archived_time_unix: z.number().int().nullable().optional(), description: z.string().nullable().optional()}); export const getPronunciationDictionariesMetadataResponseModel = z.object({pronunciation_dictionaries: z.array(getPronunciationDictionaryMetadataResponseModel), next_cursor: z.string().nullable().optional(), has_more: z.boolean()}); 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 }; /** * Get Pronunciation Dictionaries * * GET /v1/pronunciation-dictionaries */ export const getApiV1PronunciationDictionaries = async (args: GetApiV1PronunciationDictionariesArgs, options: GetApiV1PronunciationDictionariesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args.include_archived != null) query.append("include_archived", String(args.include_archived)) if (args['xi-api-key'] != null) headers.set("xi-api-key", String(args['xi-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/pronunciation-dictionaries${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 validateResponse(getPronunciationDictionariesMetadataResponseModel, await res.json()) };