import {z} from 'zod' export type UpdateEnvironmentGroupManageAccessV1 = {is_restricted: boolean, user_ids?: Array | undefined}; export type UpdateEnvironmentGroupRequestV1 = {manage_access?: (UpdateEnvironmentGroupManageAccessV1 | null) | undefined}; export type PatchApiV1TeamsTeamIdEnvironmentGroupsEnvNameArgs = {body: UpdateEnvironmentGroupRequestV1}; export type PatchApiV1TeamsTeamIdEnvironmentGroupsEnvNameOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const environmentGroupUserV1 = z.object({user_id: z.string(), email: z.string().nullable().optional(), name: z.string().nullable().optional()}); export const environmentGroupManageAccessV1 = z.object({is_restricted: z.boolean(), users: z.array(environmentGroupUserV1).optional()}); export const environmentGroupV1 = z.object({name: z.string(), team_id: z.string(), team_name: z.string(), manage_access: environmentGroupManageAccessV1}); 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 }; /** * Updates an environment group's restriction settings * * PATCH /v1/teams/{team_id}/environment_groups/{env_name} */ export const patchApiV1TeamsTeamIdEnvironmentGroupsEnvName = async (args: PatchApiV1TeamsTeamIdEnvironmentGroupsEnvNameArgs, options: PatchApiV1TeamsTeamIdEnvironmentGroupsEnvNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.team_id))}/environment_groups/${encodeURIComponent(String(args.env_name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(environmentGroupV1, await res.json()) };