import {z} from 'zod' export type GetApiV1SecretIncidentsIncidentIdInvitationsArgs = {incident_id: number, cursor?: string | undefined, per_page?: number | undefined, search?: string | undefined, ordering?: ('date' | '-date') | undefined, direct_access?: boolean | undefined}; export type GetApiV1SecretIncidentsIncidentIdInvitationsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1SecretIncidentsIncidentIdInvitationsResponse = z.array(z.object({id: z.number().int().optional(), email: z.string().optional(), role: z.enum(["manager", "member", "restricted"]).optional(), access_level: z.enum(["manager", "member", "restricted"]).optional(), date: z.string().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 }; /** * List invitations with access to a secret incident * * GET /v1/secret-incidents/{incident_id}/invitations */ export const getApiV1SecretIncidentsIncidentIdInvitations = async (args: GetApiV1SecretIncidentsIncidentIdInvitationsArgs, options?: GetApiV1SecretIncidentsIncidentIdInvitationsOptions) => { const {baseUrl = "https://api.gitguardian.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.search != null) query.append("search", String(args.search)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.direct_access != null) query.append("direct_access", String(args.direct_access)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/secret-incidents/${encodeURIComponent(String(args.incident_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(getApiV1SecretIncidentsIncidentIdInvitationsResponse, await res.json()) };