import {z} from 'zod' export type UpdateMailboxInput = {assignedUserId?: (number | null) | undefined, displayName?: (string | null) | undefined, quotaBytes?: number | undefined, status?: ('active' | 'suspended') | undefined, webhookEnabled?: boolean | undefined, forwardTo?: (string | null) | undefined, forwardMode?: ('relay' | 'wrapped') | undefined, forwardKeepCopy?: boolean | undefined, signatureHtml?: (string | null) | undefined, signatureText?: (string | null) | undefined}; export type PatchApiMailboxesIdArgs = {id: string, body: UpdateMailboxInput}; export type PatchApiMailboxesIdOptions = {baseUrl?: string | undefined, bearerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const mailbox = z.object({id: z.number().int(), publicId: z.string(), domainId: z.number().int().optional(), emailAddress: z.string(), displayName: z.string().nullable().optional(), assignedUserId: z.number().int().nullable().optional(), quotaBytes: z.number().int().nullable().optional(), usedBytes: z.number().int().nullable().optional(), status: z.enum(["active", "suspended", "deleted"]), webhookEnabled: z.boolean().optional(), forwardTo: z.string().nullable().optional(), forwardMode: z.enum(["relay", "wrapped"]).optional(), forwardKeepCopy: z.boolean().optional(), sentCount: z.number().int().optional(), lastLoginAt: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), domain: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional()}); export const patchApiMailboxesIdResponse = z.object({mailbox: mailbox}); 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 a mailbox * * PATCH /mailboxes/{id} * * Also accepts auth: bearerOAuth */ export const patchApiMailboxesId = async (args: PatchApiMailboxesIdArgs, options?: PatchApiMailboxesIdOptions) => { const {baseUrl = "https://api.poststack.dev", fetch: fetchFn = fetch, bearerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerApiKey !== undefined) headers.set('authorization', `Bearer ${bearerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/mailboxes/${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(patchApiMailboxesIdResponse, await res.json()) };