import {z} from 'zod' export type MicrosoftGraphDateTimeTimeZone = {dateTime?: string | undefined, '@odata.type'?: string | undefined, timeZone?: (string | null) | undefined}; export type MicrosoftGraphFollowupFlagStatus = 'notFlagged' | 'complete' | 'flagged'; export type MicrosoftGraphFollowupFlag = {startDateTime?: (MicrosoftGraphDateTimeTimeZone | Record | null) | undefined, dueDateTime?: (MicrosoftGraphDateTimeTimeZone | Record | null) | undefined, flagStatus?: (MicrosoftGraphFollowupFlagStatus | Record | null) | undefined, '@odata.type'?: string | undefined, completedDateTime?: (MicrosoftGraphDateTimeTimeZone | Record | null) | undefined}; export type MicrosoftGraphAttachment = {'@odata.type'?: string | undefined, id?: string | undefined, lastModifiedDateTime?: (string | null) | undefined, size?: number | undefined, name?: (string | null) | undefined, isInline?: boolean | undefined, contentType?: (string | null) | undefined, contentBytes?: (unknown | null) | undefined}; export type MicrosoftGraphImportance = 'low' | 'normal' | 'high'; export type MicrosoftGraphBodyType = 'text' | 'html'; export type MicrosoftGraphItemBody = {'@odata.type'?: string | undefined, contentType?: (MicrosoftGraphBodyType | Record | null) | undefined, content?: (string | null) | undefined}; export type MicrosoftGraphInferenceClassificationType = 'focused' | 'other'; export type MicrosoftGraphEmailAddress = {address?: (string | null) | undefined, '@odata.type'?: string | undefined, name?: (string | null) | undefined}; export type MicrosoftGraphRecipient = {emailAddress?: (MicrosoftGraphEmailAddress | Record | null) | undefined, '@odata.type'?: string | undefined}; export type MicrosoftGraphInternetMessageHeader = {'@odata.type'?: string | undefined, name?: (string | null) | undefined, value?: (string | null) | undefined}; export type MicrosoftGraphExtension = {'@odata.type'?: string | undefined, id?: string | undefined}; export type MicrosoftGraphMessage = {'@odata.type'?: string | undefined, id?: string | undefined, changeKey?: (string | null) | undefined, lastModifiedDateTime?: (string | null) | undefined, createdDateTime?: (string | null) | undefined, categories?: (Array) | undefined, flag?: (MicrosoftGraphFollowupFlag | Record | null) | undefined, attachments?: Array | undefined, parentFolderId?: (string | null) | undefined, importance?: (MicrosoftGraphImportance | Record | null) | undefined, subject?: (string | null) | undefined, webLink?: (string | null) | undefined, isDraft?: (boolean | null) | undefined, isRead?: (boolean | null) | undefined, bodyPreview?: (string | null) | undefined, body?: (MicrosoftGraphItemBody | Record | null) | undefined, inferenceClassification?: (MicrosoftGraphInferenceClassificationType | Record | null) | undefined, internetMessageId?: (string | null) | undefined, toRecipients?: Array | undefined, isReadReceiptRequested?: (boolean | null) | undefined, from?: (MicrosoftGraphRecipient | Record | null) | undefined, uniqueBody?: (MicrosoftGraphItemBody | Record | null) | undefined, hasAttachments?: (boolean | null) | undefined, sentDateTime?: (string | null) | undefined, conversationIndex?: (unknown | null) | undefined, conversationId?: (string | null) | undefined, internetMessageHeaders?: Array | undefined, receivedDateTime?: (string | null) | undefined, extensions?: Array | undefined, sender?: (MicrosoftGraphRecipient | Record | null) | undefined, bccRecipients?: Array | undefined, ccRecipients?: Array | undefined, isDeliveryReceiptRequested?: (boolean | null) | undefined, replyTo?: Array | undefined}; export type PatchApiMeMessagesMessageIdArgs = {body: MicrosoftGraphMessage}; export type PatchApiMeMessagesMessageIdOptions = {baseUrl?: string | undefined, azureOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const microsoftGraphDateTimeTimeZone = z.object({dateTime: z.string().optional(), "@odata.type": z.string().optional(), timeZone: z.string().nullable().optional()}); export const microsoftGraphFollowupFlagStatus = z.enum(["notFlagged", "complete", "flagged"]); export const microsoftGraphFollowupFlag = z.object({startDateTime: z.union([microsoftGraphDateTimeTimeZone, z.object({}).nullable()]).optional(), dueDateTime: z.union([microsoftGraphDateTimeTimeZone, z.object({}).nullable()]).optional(), flagStatus: z.union([microsoftGraphFollowupFlagStatus, z.object({}).nullable()]).optional(), "@odata.type": z.string().optional(), completedDateTime: z.union([microsoftGraphDateTimeTimeZone, z.object({}).nullable()]).optional()}); export const microsoftGraphAttachment = z.object({"@odata.type": z.string().optional(), id: z.string().optional(), lastModifiedDateTime: z.string().nullable().optional(), size: z.number().gte(-2147483648).lte(2147483647).optional(), name: z.string().nullable().optional(), isInline: z.boolean().optional(), contentType: z.string().nullable().optional(), contentBytes: z.string().nullable().optional()}); export const microsoftGraphImportance = z.enum(["low", "normal", "high"]); export const microsoftGraphBodyType = z.enum(["text", "html"]); export const microsoftGraphItemBody = z.object({"@odata.type": z.string().optional(), contentType: z.union([microsoftGraphBodyType, z.object({}).nullable()]).optional(), content: z.string().nullable().optional()}); export const microsoftGraphInferenceClassificationType = z.enum(["focused", "other"]); export const microsoftGraphEmailAddress = z.object({address: z.string().nullable().optional(), "@odata.type": z.string().optional(), name: z.string().nullable().optional()}); export const microsoftGraphRecipient = z.object({emailAddress: z.union([microsoftGraphEmailAddress, z.object({}).nullable()]).optional(), "@odata.type": z.string().optional()}); export const microsoftGraphInternetMessageHeader = z.object({"@odata.type": z.string().optional(), name: z.string().nullable().optional(), value: z.string().nullable().optional()}); export const microsoftGraphExtension = z.object({"@odata.type": z.string().optional(), id: z.string().optional()}); export const microsoftGraphMessage = z.object({"@odata.type": z.string().optional(), id: z.string().optional(), changeKey: z.string().nullable().optional(), lastModifiedDateTime: z.string().nullable().optional(), createdDateTime: z.string().nullable().optional(), categories: z.array(z.string().nullable()).optional(), flag: z.union([microsoftGraphFollowupFlag, z.object({}).nullable()]).optional(), attachments: z.array(microsoftGraphAttachment).optional(), parentFolderId: z.string().nullable().optional(), importance: z.union([microsoftGraphImportance, z.object({}).nullable()]).optional(), subject: z.string().nullable().optional(), webLink: z.string().nullable().optional(), isDraft: z.boolean().nullable().optional(), isRead: z.boolean().nullable().optional(), bodyPreview: z.string().nullable().optional(), body: z.union([microsoftGraphItemBody, z.object({}).nullable()]).optional(), inferenceClassification: z.union([microsoftGraphInferenceClassificationType, z.object({}).nullable()]).optional(), internetMessageId: z.string().nullable().optional(), toRecipients: z.array(microsoftGraphRecipient).optional(), isReadReceiptRequested: z.boolean().nullable().optional(), from: z.union([microsoftGraphRecipient, z.object({}).nullable()]).optional(), uniqueBody: z.union([microsoftGraphItemBody, z.object({}).nullable()]).optional(), hasAttachments: z.boolean().nullable().optional(), sentDateTime: z.string().nullable().optional(), conversationIndex: z.string().nullable().optional(), conversationId: z.string().nullable().optional(), internetMessageHeaders: z.array(microsoftGraphInternetMessageHeader).optional(), receivedDateTime: z.string().nullable().optional(), extensions: z.array(microsoftGraphExtension).optional(), sender: z.union([microsoftGraphRecipient, z.object({}).nullable()]).optional(), bccRecipients: z.array(microsoftGraphRecipient).optional(), ccRecipients: z.array(microsoftGraphRecipient).optional(), isDeliveryReceiptRequested: z.boolean().nullable().optional(), replyTo: z.array(microsoftGraphRecipient).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 message * * PATCH /me/messages/{messageId} */ export const patchApiMeMessagesMessageId = async (args: PatchApiMeMessagesMessageIdArgs, options?: PatchApiMeMessagesMessageIdOptions) => { const {baseUrl = "https://graph.microsoft.com/v1.0", fetch: fetchFn = fetch, azureOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (azureOAuth2 !== undefined) headers.set('authorization', `Bearer ${azureOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/me/messages/${encodeURIComponent(String(args.messageId))}${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(microsoftGraphMessage, await res.json()) };