import {z} from 'zod' export type StringFilter = {eq?: string | undefined, ne?: string | undefined, in?: string | undefined, nin?: string | undefined, between?: string | undefined, contains?: string | undefined, starts?: string | undefined, ends?: string | undefined}; export type GetApiProjectsProjectIdInvitationsArgs = {'filter[state]'?: StringFilter | undefined, 'page[size]'?: number | undefined, 'page[before]'?: string | undefined, 'page[after]'?: string | undefined, sort?: ('updated_at' | '-updated_at') | undefined}; export type GetApiProjectsProjectIdInvitationsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const projectInvitation = z.object({id: z.string().optional(), state: z.enum(["pending", "processing", "accepted", "cancelled", "error"]).optional(), project_id: z.string().optional(), role: z.enum(["admin", "viewer"]).optional(), email: z.string().optional(), owner: z.object({id: z.string().optional(), display_name: z.string().optional()}).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), finished_at: z.string().nullable().optional(), environments: z.array(z.object({id: z.string().optional(), type: z.string().optional(), role: z.enum(["admin", "viewer", "contributor"]).optional(), title: z.string().optional()})).optional()}); export const getApiProjectsProjectIdInvitationsResponse = z.array(projectInvitation); 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 invitations to a project * * GET /projects/{project_id}/invitations */ export const getApiProjectsProjectIdInvitations = async (args: GetApiProjectsProjectIdInvitationsArgs, options?: GetApiProjectsProjectIdInvitationsOptions) => { const {baseUrl = "https://api.upsun.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['filter[state]'] != null) query.append("filter[state]", JSON.stringify(args['filter[state]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args.sort != null) query.append("sort", String(args.sort)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/invitations${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(getApiProjectsProjectIdInvitationsResponse, await res.json()) };