import {z} from 'zod' export type GetApiApiV1OrganizationsOrganizationIDBillingHistoryOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const billingHistoryValues = z.object({billable_documents: z.number().int().optional(), billable_pages: z.number().int().optional(), non_billable_documents: z.number().int().optional(), non_billable_pages: z.number().int().optional(), purchased_documents: z.number().int().optional(), purchased_pages: z.number().int().optional(), extracted_pages_with_learning: z.number().int().optional(), extracted_pages_without_learning: z.number().int().optional(), split_pages_with_learning: z.number().int().optional(), split_pages_without_learning: z.number().int().optional(), extracted_documents_with_learning: z.number().int().optional(), extracted_documents_without_learning: z.number().int().optional(), split_documents_with_learning: z.number().int().optional(), split_documents_without_learning: z.number().int().optional(), ocr_only_pages: z.number().int().optional(), ocr_only_documents: z.number().int().optional(), purchased_extracted_pages_with_learning: z.number().int().optional(), purchased_extracted_pages_without_learning: z.number().int().optional(), purchased_split_pages_with_learning: z.number().int().optional(), purchased_split_pages_without_learning: z.number().int().optional(), purchased_extracted_documents_with_learning: z.number().int().optional(), purchased_extracted_documents_without_learning: z.number().int().optional(), purchased_split_documents_with_learning: z.number().int().optional(), purchased_split_documents_without_learning: z.number().int().optional(), purchased_ocr_only_pages: z.number().int().optional(), purchased_ocr_only_documents: z.number().int().optional(), is_current: z.boolean().optional()}); export const billingHistoryTotals = z.object({billable_documents: z.number().int().optional(), billable_pages: z.number().int().optional(), non_billable_documents: z.number().int().optional(), non_billable_pages: z.number().int().optional(), purchased_documents: z.number().int().optional(), purchased_pages: z.number().int().optional(), extracted_pages_with_learning: z.number().int().optional(), extracted_pages_without_learning: z.number().int().optional(), split_pages_with_learning: z.number().int().optional(), split_pages_without_learning: z.number().int().optional(), extracted_documents_with_learning: z.number().int().optional(), extracted_documents_without_learning: z.number().int().optional(), split_documents_with_learning: z.number().int().optional(), split_documents_without_learning: z.number().int().optional(), ocr_only_pages: z.number().int().optional(), ocr_only_documents: z.number().int().optional(), purchased_extracted_pages_with_learning: z.number().int().optional(), purchased_extracted_pages_without_learning: z.number().int().optional(), purchased_split_pages_with_learning: z.number().int().optional(), purchased_split_pages_without_learning: z.number().int().optional(), purchased_extracted_documents_with_learning: z.number().int().optional(), purchased_extracted_documents_without_learning: z.number().int().optional(), purchased_split_documents_with_learning: z.number().int().optional(), purchased_split_documents_without_learning: z.number().int().optional(), purchased_ocr_only_pages: z.number().int().optional(), purchased_ocr_only_documents: z.number().int().optional()}); export const getApiApiV1OrganizationsOrganizationIDBillingHistoryResponse = z.object({pagination: pagination, results: z.array(z.object({begin_date: z.string().optional(), end_date: z.string().optional(), values: billingHistoryValues.optional()})), totals: billingHistoryTotals.optional(), updated_at: 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 }; /** * Retrieve organization billing history * * GET /api/v1/organizations/{organizationID}/billing_history */ export const getApiApiV1OrganizationsOrganizationIDBillingHistory = async (options?: GetApiApiV1OrganizationsOrganizationIDBillingHistoryOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/organizations/${encodeURIComponent(String(args.organizationID))}/billing_history${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(getApiApiV1OrganizationsOrganizationIDBillingHistoryResponse, await res.json()) };