import {z} from 'zod' export type GetApiV1AccountsMeDocumentsIdArgs = {id: string, Accept?: string | undefined, page?: number | undefined, pageId?: string | undefined, crop?: string | undefined, includePageFill?: boolean | undefined}; export type GetApiV1AccountsMeDocumentsIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dataPair = z.object({name: z.string(), value: z.string().nullable()}); export const customAttribute = z.object({type: z.enum(["singleLineText", "multiLineText", "singleSelectDropdown", "multiSelectDropdown", "webLink", "numericalRange", "hierarchyDropdown"]), name: z.string().nullable().optional(), value: z.union([z.string(), z.number(), z.array(z.union([dataPair, z.string()]))]).nullable().optional()}); export const product = z.enum(["lucidchart", "lucidscale", "lucidspark"]); export const repository = z.object({repositoryId: z.string().optional()}); export const documentOwner = z.object({id: z.number().optional(), type: z.string().optional(), name: z.string().optional()}); export const document = z.object({documentId: z.string(), title: z.string(), editUrl: z.string(), viewUrl: z.string(), version: z.number().int(), pageCount: z.number().int(), canEdit: z.boolean(), created: z.string(), creatorId: z.number().int(), lastModified: z.string(), lastModifiedUserId: z.number().int(), customAttributes: z.array(customAttribute), customTags: z.array(z.string()), product: product, status: z.string().nullable().optional(), classification: z.string().nullable().optional(), classificationId: z.string().nullable().optional(), trashed: z.string().nullable().optional(), parent: z.number().int().nullable().optional(), repository: repository.nullable().optional(), accountId: z.number().int().nullable(), owner: documentOwner.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 }; /** * Get/Export Document * * GET /v1/accounts/me/documents/{id} * * Also accepts auth: OAuth2 */ export const getApiV1AccountsMeDocumentsId = async (args: GetApiV1AccountsMeDocumentsIdArgs, options?: GetApiV1AccountsMeDocumentsIdOptions) => { const {baseUrl = "https://api.lucid.co", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.page != null) query.append("page", String(args.page)) if (args.pageId != null) query.append("pageId", String(args.pageId)) if (args.crop != null) query.append("crop", String(args.crop)) if (args.includePageFill != null) query.append("includePageFill", String(args.includePageFill)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/me/documents/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(document, await res.json()) };