import {z} from 'zod' export type DeleteApiAmsClientIDMemberMemberIDMessagesMessageIdArgs = {MessageIds?: string | undefined, MessageId: number, SenderId?: number | undefined, UpdateAction?: ('None' | 'Read' | 'Unread' | 'Archive' | 'Move') | undefined, FolderType?: ('Inbox' | 'Sent' | 'Deleted' | 'Draft' | 'Junk' | 'Personal') | undefined, Subject?: string | undefined, Body?: string | undefined, RecipientId?: number | undefined, FolderId?: number | undefined, MessageTypeId?: string | undefined, IsRichText?: boolean | undefined, Expires?: string | undefined, DateShow?: string | undefined, AttachmentPath?: string | undefined, SenderName?: string | undefined, RecipientName?: string | undefined, AttachmentSize?: number | undefined, PageSize?: number | undefined, PageNumber?: number | undefined, Attachment?: string | undefined, AttachmentName?: string | undefined, MemberID: number, ClientID: number, ResponseStatus?: string | undefined, BypassCache?: boolean | undefined, DateCached?: string | undefined, Device?: string | undefined}; export type DeleteApiAmsClientIDMemberMemberIDMessagesMessageIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const dictionaryStringString = z.record(z.string(), z.string()); export const responseError = z.object({ErrorCode: z.string().optional(), FieldName: z.string().optional(), Message: z.string().optional(), Meta: dictionaryStringString.optional()}); export const responseStatus = z.object({ErrorCode: z.string().optional(), Message: z.string().optional(), StackTrace: z.string().optional(), Errors: z.array(responseError).optional(), Meta: dictionaryStringString.optional()}); export const messageResponse = z.object({FolderName: z.string().optional(), MessageDate: z.string().optional(), IsRead: z.boolean().optional(), HasAttachments: z.boolean().optional(), SenderHeadshotImage: z.string().optional(), RecipientHeadshotImage: z.string().optional(), MessageIds: z.array(z.number().int()).optional(), MessageId: z.number().int().optional(), SenderId: z.number().int().optional(), UpdateAction: z.enum(["None", "Read", "Unread", "Archive", "Move"]).optional(), FolderType: z.enum(["Inbox", "Sent", "Deleted", "Draft", "Junk", "Personal"]).optional(), Subject: z.string().optional(), Body: z.string().optional(), RecipientId: z.number().int().optional(), FolderId: z.number().int().optional(), MessageTypeId: z.string().optional(), IsRichText: z.boolean().optional(), Expires: z.string().optional(), DateShow: z.string().optional(), AttachmentPath: z.string().optional(), SenderName: z.string().optional(), RecipientName: z.string().optional(), AttachmentSize: z.number().int().optional(), PageSize: z.number().int().optional(), PageNumber: z.number().int().optional(), Attachment: z.string().optional(), AttachmentName: z.string().optional(), MemberID: z.number().int().optional(), ClientID: z.number().int().optional(), ResponseStatus: responseStatus.optional(), BypassCache: z.boolean().optional(), DateCached: z.string().optional(), Device: z.string().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 }; /** * Delete a message. * * DELETE /Ams/{ClientID}/Member/{MemberID}/Messages/{MessageId} */ export const deleteApiAmsClientIDMemberMemberIDMessagesMessageId = async (args: DeleteApiAmsClientIDMemberMemberIDMessagesMessageIdArgs, options?: DeleteApiAmsClientIDMemberMemberIDMessagesMessageIdOptions) => { const {baseUrl = "https://ws.yourmembership.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.MessageIds != null) query.append("MessageIds", String(args.MessageIds)) if (args.SenderId != null) query.append("SenderId", String(args.SenderId)) if (args.UpdateAction != null) query.append("UpdateAction", String(args.UpdateAction)) if (args.FolderType != null) query.append("FolderType", String(args.FolderType)) if (args.Subject != null) query.append("Subject", String(args.Subject)) if (args.Body != null) query.append("Body", String(args.Body)) if (args.RecipientId != null) query.append("RecipientId", String(args.RecipientId)) if (args.FolderId != null) query.append("FolderId", String(args.FolderId)) if (args.MessageTypeId != null) query.append("MessageTypeId", String(args.MessageTypeId)) if (args.IsRichText != null) query.append("IsRichText", String(args.IsRichText)) if (args.Expires != null) query.append("Expires", String(args.Expires)) if (args.DateShow != null) query.append("DateShow", String(args.DateShow)) if (args.AttachmentPath != null) query.append("AttachmentPath", String(args.AttachmentPath)) if (args.SenderName != null) query.append("SenderName", String(args.SenderName)) if (args.RecipientName != null) query.append("RecipientName", String(args.RecipientName)) if (args.AttachmentSize != null) query.append("AttachmentSize", String(args.AttachmentSize)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.PageNumber != null) query.append("PageNumber", String(args.PageNumber)) if (args.Attachment != null) query.append("Attachment", String(args.Attachment)) if (args.AttachmentName != null) query.append("AttachmentName", String(args.AttachmentName)) if (args.ResponseStatus != null) query.append("ResponseStatus", String(args.ResponseStatus)) if (args.BypassCache != null) query.append("BypassCache", String(args.BypassCache)) if (args.DateCached != null) query.append("DateCached", String(args.DateCached)) if (args.Device != null) query.append("Device", String(args.Device)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/Ams/${encodeURIComponent(String(args.ClientID))}/Member/${encodeURIComponent(String(args.MemberID))}/Messages/${encodeURIComponent(String(args.MessageId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(messageResponse, await res.json()) };