import {z} from 'zod' export type GetApiApiAtlasV2OrgsOrgIdInvitesInvitationIdArgs = {envelope?: boolean | undefined, orgId: string, invitationId: string}; export type GetApiApiAtlasV2OrgsOrgIdInvitesInvitationIdOptions = {baseUrl?: string | undefined, ServiceAccounts?: string | undefined, fetch?: typeof fetch | undefined}; export const groupRole = z.object({groupId: z.string().optional(), groupRole: z.string().optional()}); export const link = z.object({href: z.string().optional(), rel: z.string().optional()}); export const organizationInvitation = z.object({createdAt: z.string().optional(), expiresAt: z.string().optional(), groupRoleAssignments: z.array(groupRole).optional(), id: z.string().optional(), inviterUsername: z.string().optional(), links: z.array(link).optional(), orgId: z.string().optional(), orgName: z.string(), roles: z.array(z.enum(["ORG_OWNER", "ORG_MEMBER", "ORG_GROUP_CREATOR", "ORG_BILLING_ADMIN", "ORG_BILLING_READ_ONLY", "ORG_STREAM_PROCESSING_ADMIN", "ORG_READ_ONLY"])).optional(), teamIds: z.array(z.string()).optional(), username: z.string().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 }; /** * Return One Invitation in One Organization by Invitation ID * * GET /api/atlas/v2/orgs/{orgId}/invites/{invitationId} * * Also accepts auth: DigestAuth */ export const getApiApiAtlasV2OrgsOrgIdInvitesInvitationId = async (args: GetApiApiAtlasV2OrgsOrgIdInvitesInvitationIdArgs, options?: GetApiApiAtlasV2OrgsOrgIdInvitesInvitationIdOptions) => { const {baseUrl = "https://cloud.mongodb.com", fetch: fetchFn = fetch, ServiceAccounts} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.atlas.2023-01-01+json") if (args.envelope != null) query.append("envelope", String(args.envelope)) if (ServiceAccounts !== undefined) headers.set('authorization', `Bearer ${ServiceAccounts}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/atlas/v2/orgs/${encodeURIComponent(String(args.orgId))}/invites/${encodeURIComponent(String(args.invitationId))}${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(organizationInvitation, await res.json()) };