import {z} from 'zod' export type PatchApiPublicUserServiceEditServiceIdArgs = {service_id: string, 'Content-Type': string, body: {cancel_comment?: string | undefined, cancel_feedback?: string | undefined, payment_method_id?: string | undefined, service_is_automatic_collection?: boolean | undefined, service_is_pending_cancellation?: boolean | undefined, service_metadata?: Record | undefined}}; export type PatchApiPublicUserServiceEditServiceIdOptions = {baseUrl?: string | undefined, APIPrivateKey?: string | undefined, APIPublicKey?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiPublicUserServiceEditServiceIdResponse = z.object({edited: z.array(z.string()).optional(), message: z.string().optional()}); 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 }; /** * Edit Service * * PATCH /public/user/service/edit/{service_id} */ export const patchApiPublicUserServiceEditServiceId = async (args: PatchApiPublicUserServiceEditServiceIdArgs, options?: PatchApiPublicUserServiceEditServiceIdOptions) => { const {baseUrl = "https://api.byteful.com/1.0", fetch: fetchFn = fetch, APIPrivateKey, APIPublicKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (APIPrivateKey !== undefined) headers.set("X-API-Private-Key", APIPrivateKey) if (APIPublicKey !== undefined) headers.set("X-API-Public-Key", APIPublicKey) const url = `${baseUrl.replace(/\/+$/, '')}/public/user/service/edit/${encodeURIComponent(String(args.service_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiPublicUserServiceEditServiceIdResponse, await res.json()) };