import {z} from 'zod' export type GetApiV3BundlesBundleIdFollowUpChatsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const managingFollowUpChat = z.object({bundle_id: z.number().int().optional(), change_status: z.boolean().optional(), hours_after: z.number().int().optional(), id: z.number().int().optional(), image: z.string().optional(), is_default: z.boolean().optional(), name: z.string().optional(), product_id: z.number().int().optional(), provider: z.string().optional(), store_id: z.number().int().optional(), text_for_bank_transfer: z.string().optional(), text_for_cod: z.string().optional(), text_for_epayment: z.string().optional(), trigger: z.string().optional(), wa_gateway_assignation_type: z.string().optional(), wa_integration: z.object({id: z.number().int().optional(), name: z.string().optional(), phone_number: z.string().optional(), provider: z.string().optional()}).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 }; /** * Get a bundle follow-up chat * * GET /v3/bundles/{bundle_id}/follow-up-chats/{id} * * Also accepts auth: apiKeyAuth */ export const getApiV3BundlesBundleIdFollowUpChatsId = async (options?: GetApiV3BundlesBundleIdFollowUpChatsIdOptions) => { const {baseUrl = "https://api.scalev.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/bundles/${encodeURIComponent(String(args.bundle_id))}/follow-up-chats/${encodeURIComponent(String(args.id))}${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(managingFollowUpChat, await res.json()) };