import {z} from 'zod' export type GetApiPublicV1ClonesCloneIdIntegrationsArgs = {cloneId: string, type?: ('Slack' | 'Email' | 'MsTeams' | 'Phone') | undefined}; export type GetApiPublicV1ClonesCloneIdIntegrationsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const slackDetail = z.object({teamId: z.string().optional(), teamName: z.string().optional()}); export const emailDetail = z.object({email: z.string(), connectionType: z.string().optional()}); export const msTeamsTeamRef = z.object({id: z.string(), name: z.string()}); export const msTeamsDetail = z.object({organizationName: z.string().optional(), teams: z.array(msTeamsTeamRef).optional()}); export const phoneDetail = z.object({phoneNumber: z.string().optional()}); export const integrationSummary = z.object({id: z.string(), type: z.enum(["Slack", "Email", "MsTeams", "Phone"]), status: z.enum(["Pending", "Connected", "Error", "Provisioning"]), name: z.string().optional(), errorMessage: z.string().optional(), detail: z.union([slackDetail, emailDetail, msTeamsDetail, phoneDetail]).optional(), createdAt: z.string(), updatedAt: z.string()}); export const getApiPublicV1ClonesCloneIdIntegrationsResponse = z.object({data: z.array(integrationSummary)}); 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 }; /** * List integrations * * GET /public/v1/clones/{cloneId}/integrations */ export const getApiPublicV1ClonesCloneIdIntegrations = async (args: GetApiPublicV1ClonesCloneIdIntegrationsArgs, options?: GetApiPublicV1ClonesCloneIdIntegrationsOptions) => { const {baseUrl = "https://api.cloneforce.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/clones/${encodeURIComponent(String(args.cloneId))}/integrations${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(getApiPublicV1ClonesCloneIdIntegrationsResponse, await res.json()) };