import {z} from 'zod' export type Product = 'lucidchart' | 'lucidscale' | 'lucidspark'; export type CreateApiV2AccountsMeDocumentsSearchArgs = {'Lucid-Request-As': string, body: {userIds?: Array | undefined, ownedByUsers?: boolean | undefined, documentIds?: Array | undefined, classificationIds?: Array | undefined, statusIds?: Array | undefined, createdStartTime?: string | undefined, createdEndTime?: string | undefined, lastModifiedStartTime?: string | undefined, lastModifiedEndTime?: string | undefined, product?: Array | undefined, keywords?: string | undefined, documentLocation?: ('team folders' | 'users' | 'deleted' | 'repositories') | undefined, externalAccess?: ('any' | 'external-collaborators' | 'external-links') | undefined}}; export type CreateApiV2AccountsMeDocumentsSearchOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const product = z.enum(["lucidchart", "lucidscale", "lucidspark"]); export const accountDocumentV2 = z.object({documentId: z.string(), title: z.string(), adminViewUrl: z.string(), created: z.string(), owner: z.object({ownerType: z.string().optional(), id: z.number().optional(), resourceType: z.enum(["team", "teamFolder", "repository"]).nullable().optional(), resourceId: z.string().nullable().optional()}), lastModified: z.string(), trashed: z.string().nullable().optional(), customTags: z.array(z.string()), product: product, status: z.string().nullable().optional(), classification: z.string().nullable().optional(), parent: z.number().int().nullable().optional(), userCollaboratorIds: z.array(z.number().int()), teamCollaboratorIds: z.array(z.string())}); export const createApiV2AccountsMeDocumentsSearchResponse = z.array(accountDocumentV2); 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 }; /** * Search Account Documents * * POST /v2/accounts/me/documents/search * * Also accepts auth: OAuth2 */ export const createApiV2AccountsMeDocumentsSearch = async (args: CreateApiV2AccountsMeDocumentsSearchArgs, options?: CreateApiV2AccountsMeDocumentsSearchOptions) => { const {baseUrl = "https://api.lucid.co", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Lucid-Request-As'] != null) headers.set("Lucid-Request-As", String(args['Lucid-Request-As'])) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/accounts/me/documents/search${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(createApiV2AccountsMeDocumentsSearchResponse, await res.json()) };