import {z} from 'zod' export type HelpDeskSettingsChange = {patch: {customer_auth_preference?: ('identity' | 'email_pin') | undefined, operator_display?: ({name_format?: ('first_last_initial' | 'full_name' | 'generic') | undefined, avatar_mode?: ('authsv' | 'generic') | undefined, generic_label?: string | undefined}) | undefined, status_after_reply?: ('waiting_on_customer' | 'open') | undefined, auto_assign_on_first_reply?: boolean | undefined, customer_can_mark_resolved?: boolean | undefined, feedback_positive_url?: (string | null) | undefined, feedback_negative_url?: (string | null) | undefined, email_content_mode?: ('full' | 'notify_only') | undefined, accept_email_replies?: boolean | undefined, custom_domain?: (string | null) | undefined, customer_upload_limit_bytes?: (number | null) | undefined, branding?: ({color?: (string | null) | undefined}) | undefined}, version: number}; export type UpdateApiProductsHelpDeskSettingsArgs = {body: HelpDeskSettingsChange}; export type UpdateApiProductsHelpDeskSettingsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const helpDeskOperatorDisplay = z.object({name_format: z.enum(["first_last_initial", "full_name", "generic"]), avatar_mode: z.enum(["authsv", "generic"]), generic_label: z.string().max(40)}); export const helpDeskSettings = z.object({vault_id: z.string().nullable(), activated_at: z.number().int().nullable(), deactivated_at: z.number().int().nullable(), customer_auth_preference: z.enum(["identity", "email_pin"]), operator_display: helpDeskOperatorDisplay, status_after_reply: z.enum(["waiting_on_customer", "open"]), auto_assign_on_first_reply: z.boolean(), customer_can_mark_resolved: z.boolean(), feedback_positive_url: z.string().max(2048).nullable(), feedback_negative_url: z.string().max(2048).nullable(), email_content_mode: z.enum(["full", "notify_only"]), accept_email_replies: z.boolean(), custom_domain: z.string().nullable(), customer_upload_limit_bytes: z.number().int().gte(0).nullable(), branding: z.object({color: z.string().nullable()}), version: z.number().int()}); export const responseMeta = z.object({api_version: z.string().optional(), request_id: z.string().optional(), response_ms: z.number().int().optional(), timestamp: z.number().int().optional(), pools: z.object({}).optional(), billing: z.object({past_due: z.boolean().optional()}).optional(), quota: z.object({limit: z.number().int().optional(), used: z.number().int().optional(), remaining: z.number().int().optional(), resets_at: z.number().int().optional()}).optional()}); export const updateApiProductsHelpDeskSettingsResponse = z.object({data: helpDeskSettings, meta: responseMeta.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 }; /** * Change the help desk settings * * PUT /products/help-desk/settings */ export const updateApiProductsHelpDeskSettings = async (args: UpdateApiProductsHelpDeskSettingsArgs, options?: UpdateApiProductsHelpDeskSettingsOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", 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(/\/+$/, '')}/products/help-desk/settings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiProductsHelpDeskSettingsResponse, await res.json()) };