import {z} from 'zod' export type GetApiApiPreviewSharedWithMeArgs = {before?: string | undefined, before_id?: string | undefined, ws?: string | undefined}; export type GetApiApiPreviewSharedWithMeOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPreviewSharedWithMeResponse = z.object({hasMore: z.boolean(), items: z.array(z.object({access: z.enum(["view", "edit"]), grant_id: z.string().max(36), owner_name: z.string().max(200), resource_id: z.string().max(36), resource_type: z.enum(["capsule", "type", "collection"]), shared_at: z.string().max(64), title: z.string().max(500), type_id: z.string().max(36).nullable(), url: z.string().max(200)}))}); 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 }; /** * List what other people shared with you by name * * GET /api/preview/shared-with-me * * Also accepts auth: cookieAuth, oauth2 */ export const getApiApiPreviewSharedWithMe = async (args: GetApiApiPreviewSharedWithMeArgs, options: GetApiApiPreviewSharedWithMeOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.before != null) query.append("before", String(args.before)) if (args.before_id != null) query.append("before_id", String(args.before_id)) if (args.ws != null) query.append("ws", String(args.ws)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/shared-with-me${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(getApiApiPreviewSharedWithMeResponse, await res.json()) };