import {z} from 'zod' export type GetApiApiAtlasV2OrgsOrgIdInvoicesInvoiceIdArgs = {envelope?: boolean | undefined, orgId: string, pretty?: boolean | undefined, invoiceId: string}; export type GetApiApiAtlasV2OrgsOrgIdInvoicesInvoiceIdOptions = {baseUrl?: string | undefined, ServiceAccounts?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceLineItem = z.object({clusterName: z.string().optional(), created: z.string().optional(), discountCents: z.number().int().optional(), endDate: z.string().optional(), groupId: z.string().optional(), groupName: z.string().optional(), note: z.string().optional(), percentDiscount: z.number().optional(), quantity: z.number().optional(), sku: z.string().optional(), startDate: z.string().optional(), stitchAppName: z.string().optional(), tags: z.record(z.string(), z.array(z.string())).optional(), tierLowerBound: z.number().optional(), tierUpperBound: z.number().optional(), totalPriceCents: z.number().int().optional(), unit: z.string().optional(), unitPriceDollars: z.number().optional()}); export const link = z.object({href: z.string().optional(), rel: z.string().optional()}); export const billingPayment = z.object({amountBilledCents: z.number().int().optional(), amountPaidCents: z.number().int().optional(), created: z.string().optional(), currency: z.string().optional(), id: z.string().optional(), salesTaxCents: z.number().int().optional(), statusName: z.enum(["NEW", "FORGIVEN", "FAILED", "PAID", "PARTIAL_PAID", "CANCELLED", "INVOICED", "FAILED_AUTHENTICATION", "PROCESSING", "PENDING_REVERSAL", "REFUNDED"]).optional(), subtotalCents: z.number().int().optional(), unitPrice: z.string().optional(), updated: z.string().optional()}); export const billingRefund = z.object({amountCents: z.number().int().optional(), created: z.string().optional(), paymentId: z.string().optional(), reason: z.string().optional()}); export const billingInvoice: z.ZodType = z.object({amountBilledCents: z.number().int().optional(), amountPaidCents: z.number().int().optional(), created: z.string().optional(), creditsCents: z.number().int().optional(), endDate: z.string().optional(), id: z.string().optional(), lineItems: z.array(invoiceLineItem).optional(), linkedInvoices: z.array(z.lazy(() => billingInvoice)).optional(), links: z.array(link).optional(), orgId: z.string().optional(), payments: z.array(billingPayment).optional(), refunds: z.array(billingRefund).optional(), salesTaxCents: z.number().int().optional(), startDate: z.string().optional(), startingBalanceCents: z.number().int().optional(), statusName: z.enum(["PENDING", "CLOSED", "FORGIVEN", "FAILED", "PAID", "FREE", "PREPAID", "INVOICED"]).optional(), subtotalCents: z.number().int().optional(), updated: 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 Invoice for One Organization * * GET /api/atlas/v2/orgs/{orgId}/invoices/{invoiceId} * * Also accepts auth: DigestAuth */ export const getApiApiAtlasV2OrgsOrgIdInvoicesInvoiceId = async (args: GetApiApiAtlasV2OrgsOrgIdInvoicesInvoiceIdArgs, options?: GetApiApiAtlasV2OrgsOrgIdInvoicesInvoiceIdOptions) => { 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 (args.pretty != null) query.append("pretty", String(args.pretty)) if (ServiceAccounts !== undefined) headers.set('authorization', `Bearer ${ServiceAccounts}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/atlas/v2/orgs/${encodeURIComponent(String(args.orgId))}/invoices/${encodeURIComponent(String(args.invoiceId))}${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(billingInvoice, await res.json()) };