import {z} from 'zod' export type GetApiV1IncidentsSecretsIncidentIdMembersArgs = {incident_id: number, cursor?: string | undefined, page?: number | undefined, per_page?: number | undefined, member_id?: number | undefined, incident_permission?: ('can_view' | 'can_edit' | 'full_access') | undefined, role?: ('owner' | 'manager' | 'member' | 'restricted') | undefined, search?: string | undefined}; export type GetApiV1IncidentsSecretsIncidentIdMembersOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1IncidentsSecretsIncidentIdMembersResponse = z.array(z.object({member_id: z.number().int().optional(), incident_id: z.number().int().optional(), incident_permission: z.enum(["can_view", "can_edit", "full_access"]).optional(), id: z.number().int().optional(), name: z.string().optional(), email: z.string().optional(), role: z.enum(["owner", "manager", "member", "restricted"]).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 members having access to a secret incident * * GET /v1/incidents/secrets/{incident_id}/members */ export const getApiV1IncidentsSecretsIncidentIdMembers = async (args: GetApiV1IncidentsSecretsIncidentIdMembersArgs, options?: GetApiV1IncidentsSecretsIncidentIdMembersOptions) => { 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.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.member_id != null) query.append("member_id", String(args.member_id)) if (args.incident_permission != null) query.append("incident_permission", String(args.incident_permission)) if (args.role != null) query.append("role", String(args.role)) if (args.search != null) query.append("search", String(args.search)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/incidents/secrets/${encodeURIComponent(String(args.incident_id))}/members${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(getApiV1IncidentsSecretsIncidentIdMembersResponse, await res.json()) };