import {z} from 'zod' export type SlackInstallation = {id?: string | undefined, created?: string | undefined, modified?: string | undefined, enterprise_id?: (string | null) | undefined, team_id: string, bot_token: string, bot_id: string, bot_user_id: string, webhook_channel_name?: (string | null) | undefined, webhook_channel_id?: string | undefined, webhook_configuration_url?: (string | null) | undefined, webhook_url?: string | undefined, is_uninstalled?: boolean | undefined, last_install_date?: (string | null) | undefined}; export type CreateApiApiCompaniesInstallationsArgs = {body: SlackInstallation}; export type CreateApiApiCompaniesInstallationsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const slackInstallation = z.object({id: z.string().optional(), created: z.string().optional(), modified: z.string().optional(), enterprise_id: z.string().max(255).nullable().optional(), team_id: z.string().min(1).max(255), bot_token: z.string().min(1).max(1000), bot_id: z.string().min(1).max(255), bot_user_id: z.string().min(1).max(255), webhook_channel_name: z.string().max(255).nullable().optional(), webhook_channel_id: z.string().max(255).optional(), webhook_configuration_url: z.string().max(255).nullable().optional(), webhook_url: z.string().max(255).optional(), is_uninstalled: z.boolean().optional(), last_install_date: z.string().nullable().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 }; /** * POST /api/companies/installations */ export const createApiApiCompaniesInstallations = async (args: CreateApiApiCompaniesInstallationsArgs, options?: CreateApiApiCompaniesInstallationsOptions) => { const {baseUrl = "https://app.haekka.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/companies/installations${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(slackInstallation, await res.json()) };