import {z} from 'zod' export type CreateApiProductsHelpDeskDeactivateOptions = {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 createApiProductsHelpDeskDeactivateResponse = z.object({data: helpDeskSettings.nullable(), 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 }; /** * Deactivate the help desk * * POST /products/help-desk/deactivate */ export const createApiProductsHelpDeskDeactivate = async (options?: CreateApiProductsHelpDeskDeactivateOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", 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(/\/+$/, '')}/products/help-desk/deactivate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiProductsHelpDeskDeactivateResponse, await res.json()) };