import {z} from 'zod' export type BetaCreateInviteParams = {email: string, rbac_group_ids?: Array | undefined, role: 'billing' | 'claude_code_user' | 'developer' | 'managed' | 'user'}; export type CreateApiV1OrganizationsInvitesBetaTrueArgs = {'anthropic-version'?: string | undefined, body: BetaCreateInviteParams}; export type CreateApiV1OrganizationsInvitesBetaTrueOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const betaOrganizationRoleSchema = z.enum(["admin", "billing", "claude_code_user", "developer", "managed", "membership_admin", "owner", "primary_owner", "user"]); export const betaInviteStatusSchema = z.enum(["accepted", "deleted", "expired", "pending"]); export const betaInviteSchema = z.object({accepted_at: z.string().nullable(), email: z.string(), expires_at: z.string(), id: z.string(), invited_at: z.string(), rbac_group_ids: z.array(z.string()), role: betaOrganizationRoleSchema, status: betaInviteStatusSchema, type: z.literal("invite")}); 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 }; /** * Create Invite * * POST /v1/organizations/invites?beta=true */ export const createApiV1OrganizationsInvitesBetaTrue = async (args: CreateApiV1OrganizationsInvitesBetaTrueArgs, options?: CreateApiV1OrganizationsInvitesBetaTrueOptions) => { const {baseUrl = "https://api.anthropic.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['anthropic-version'] != null) headers.set("anthropic-version", String(args['anthropic-version'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/invites?beta=true${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(betaInviteSchema, await res.json()) };