import {z} from 'zod' export type RenameOrganizationRequest = {display_name: string}; export type PatchApiApiV1OrganizationsOrganizationIdArgs = {organization_id: string, body: RenameOrganizationRequest}; export type PatchApiApiV1OrganizationsOrganizationIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationInfo = z.object({organization_id: z.string(), name: z.string(), display_name: z.string(), role: z.enum(["owner", "admin", "member"]), rate_limit_rpm: z.number().int(), included_credits: z.number().int().nullable().optional(), joined_at: z.string(), created_at: z.string(), default_workspace_id: z.string().nullable().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 }; /** * Rename Organization * * PATCH /api/v1/organizations/{organization_id} */ export const patchApiApiV1OrganizationsOrganizationId = async (args: PatchApiApiV1OrganizationsOrganizationIdArgs, options: PatchApiApiV1OrganizationsOrganizationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/organizations/${encodeURIComponent(String(args.organization_id))}${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(organizationInfo, await res.json()) };