import {z} from 'zod' export type DriveItemSourceApplication = 'teams' | 'yammer' | 'sharePoint' | 'oneDrive' | 'stream' | 'powerPoint' | 'office' | 'loki' | 'loop' | 'other' | 'unknownFutureValue'; export type DriveItemSource = {application?: DriveItemSourceApplication | undefined, externalId?: (string | null) | undefined} | {[key: string]: unknown}; export type FileSystemInfo = {createdDateTime?: (string | null) | undefined, lastAccessedDateTime?: (string | null) | undefined, lastModifiedDateTime?: (string | null) | undefined} | {[key: string]: unknown}; export type MediaSourceContentCategory = 'meeting' | 'liveStream' | 'presentation' | 'screenRecording' | 'story' | 'profile' | 'chat' | 'note' | 'comment' | 'unknownFutureValue'; export type MediaSource = {contentCategory?: MediaSourceContentCategory | undefined} | {[key: string]: unknown}; export type DriveItemUploadableProperties = {description?: (string | null) | undefined, driveItemSource?: DriveItemSource | undefined, fileSize?: (number | null) | undefined, fileSystemInfo?: FileSystemInfo | undefined, mediaSource?: MediaSource | undefined, name?: (string | null) | undefined} | {[key: string]: unknown}; export type DriveItemIdMicrosoftGraphCreateUploadSessionBody = {item?: DriveItemUploadableProperties | undefined} | {[key: string]: unknown}; export type CreateApiDrivesDriveIdRootMicrosoftGraphCreateUploadSessionArgs = {driveId: string, body: DriveItemIdMicrosoftGraphCreateUploadSessionBody}; export type CreateApiDrivesDriveIdRootMicrosoftGraphCreateUploadSessionOptions = {baseUrl?: string | undefined, azureaadv2?: string | undefined, fetch?: typeof fetch | undefined}; export const uploadSession = z.object({expirationDateTime: z.string().nullable().optional(), nextExpectedRanges: z.array(z.string().nullable()).optional(), uploadUrl: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Invoke action createUploadSession * * POST /drives/{driveId}/root/microsoft.graph.createUploadSession */ export const createApiDrivesDriveIdRootMicrosoftGraphCreateUploadSession = async (args: CreateApiDrivesDriveIdRootMicrosoftGraphCreateUploadSessionArgs, options?: CreateApiDrivesDriveIdRootMicrosoftGraphCreateUploadSessionOptions) => { const {baseUrl = "https://graph.microsoft.com/v1.0", fetch: fetchFn = fetch, azureaadv2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (azureaadv2 !== undefined) headers.set('authorization', `Bearer ${azureaadv2}`) const url = `${baseUrl.replace(/\/+$/, '')}/drives/${encodeURIComponent(String(args.driveId))}/root/microsoft.graph.createUploadSession${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(uploadSession, await res.json()) };