import {z} from 'zod' export type UpdateTeamRequest = {name?: string | undefined, domain?: string | undefined, logo?: string | undefined, about?: string | undefined, meeting_link?: string | undefined, meeting_link_text?: string | undefined, auto_placement_testing?: boolean | undefined, auto_placement_testing_frequency?: (7 | 14 | 30) | undefined, inbox_auto_tag_settings?: ({auto_tag_bounced?: boolean | undefined, auto_tag_opt_out?: boolean | undefined, auto_tag_out_of_office?: boolean | undefined}) | undefined, inbox_super_views?: (Array<{id: string, name: string, icon: string, filters: {mood?: ('positive' | 'negative' | 'neutral' | 'needs_review') | undefined, statuses?: Array | undefined, lastMessageDirection?: ('inbound' | 'outbound') | undefined, labels?: Array | undefined}, visible?: boolean | undefined, order?: number | undefined}>) | undefined}; export type PatchApiTeamsIdArgs = {id: string, body: UpdateTeamRequest}; export type PatchApiTeamsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const team = z.object({id: z.string().optional(), name: z.string().optional(), domain: z.string().optional(), logo: z.string().optional(), about: z.string().optional(), is_default: z.boolean().optional(), meeting_link: z.string().optional(), meeting_link_text: z.string().optional(), auto_placement_testing: z.boolean().optional(), inbox_auto_tag_settings: z.object({}).optional(), inbox_super_views: z.array(z.object({id: z.string().optional(), name: z.string().optional(), icon: z.string().optional(), filters: z.object({mood: z.enum(["positive", "negative", "neutral", "needs_review"]).optional(), statuses: z.array(z.string()).optional(), lastMessageDirection: z.enum(["inbound", "outbound"]).optional(), labels: z.array(z.string()).optional()}).optional(), visible: z.boolean().optional(), order: z.number().int().optional()})).optional(), member_count: z.number().int().optional(), organization: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const teamResponse = z.object({success: z.boolean().optional(), request_id: z.string().optional(), data: team.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 }; /** * Update Team * * PATCH /teams/{id} */ export const patchApiTeamsId = async (args: PatchApiTeamsIdArgs, options?: PatchApiTeamsIdOptions) => { const {baseUrl = "https://api.supersend.io/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/teams/${encodeURIComponent(String(args.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(teamResponse, await res.json()) };