import {z} from 'zod' export type GetApiApiPreviewCapsulesIdPermissionsArgs = {id: string}; export type GetApiApiPreviewCapsulesIdPermissionsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPreviewCapsulesIdPermissionsResponse = z.object({effective: z.object({can_update: z.boolean()}).and(z.record(z.string(), z.unknown())), in_library_share: z.boolean(), organizationId: z.string().max(128).nullable(), organizationName: z.string().max(200).nullable(), reachableThrough: z.array(z.object({id: z.string().max(128), kind: z.enum(["type", "collection", "link", "project"]), name: z.string().max(2000), slug: z.string().max(200), visibility: z.enum(["link", "public"])}).and(z.record(z.string(), z.unknown()))), sharedWithPeople: z.object({archived: z.boolean(), count: z.number().int().gte(0).lte(9007199254740991), direct: z.number().int().gte(0).lte(9007199254740991), viewerIsOwner: z.boolean()}).and(z.record(z.string(), z.unknown())).nullable().optional(), shared_since: z.string().max(64).nullable(), visibility: z.enum(["self", "link", "public", "org_view", "org_edit"])}).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 }; /** * Read a capsule's visibility, the links it is reachable through, how many people it is shared with, and your own access to it * * GET /api/preview/capsules/{id}/permissions * * Also accepts auth: cookieAuth, oauth2 */ export const getApiApiPreviewCapsulesIdPermissions = async (args: GetApiApiPreviewCapsulesIdPermissionsArgs, options: GetApiApiPreviewCapsulesIdPermissionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/capsules/${encodeURIComponent(String(args.id))}/permissions${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(getApiApiPreviewCapsulesIdPermissionsResponse, await res.json()) };