import {z} from 'zod' export type TeamMemberCreate = {email: string, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, role?: ('member' | 'admin') | undefined, send_invitation?: boolean | undefined}; export type CreateApiV1EnterpriseTeamsTeamIdInvitationsArgs = {team_id: number, body: TeamMemberCreate}; export type CreateApiV1EnterpriseTeamsTeamIdInvitationsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const teamInvitationResponse = z.object({role: z.string().optional(), id: z.number().int(), team_id: z.number().int(), email: z.string(), first_name: z.string().nullable(), last_name: z.string().nullable(), invited_by_id: z.number().int(), status: z.string(), invited_at: z.string(), responded_at: z.string().nullable(), expires_at: z.string()}); 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 }; /** * Invite Team Member * * POST /v1/enterprise/teams/{team_id}/invitations */ export const createApiV1EnterpriseTeamsTeamIdInvitations = async (args: CreateApiV1EnterpriseTeamsTeamIdInvitationsArgs, options: CreateApiV1EnterpriseTeamsTeamIdInvitationsOptions) => { 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(/\/+$/, '')}/v1/enterprise/teams/${encodeURIComponent(String(args.team_id))}/invitations${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(teamInvitationResponse, await res.json()) };