import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdFeaturesFeatureIdWhitelabelDashboardArgs = {projectId: string, featureId: string}; export type GetApiRestApiV1ProjectsProjectIdFeaturesFeatureIdWhitelabelDashboardOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceSummaryDTO = z.object({amount: z.number().optional(), created: z.string().optional(), customerEmail: z.string().optional(), description: z.string().optional(), discount: z.number().optional(), dueDate: z.string().optional(), invoiceNumber: z.string().optional(), manualCollection: z.boolean().optional(), projectId: z.string().optional(), status: z.string().optional()}); export const customerSummaryDTO = z.object({accountCount: z.number().int().optional(), activeProjectCount: z.number().int().optional(), blocked: z.boolean().optional(), created: z.string().optional(), currentMonthOutstanding: z.number().optional(), customerId: z.number().int().optional(), email: z.string().optional(), openInvoices: z.array(invoiceSummaryDTO).optional(), outstandingAmount: z.number().optional(), paidAmount: z.number().optional(), permission: z.string().optional(), projectIds: z.array(z.string()).optional()}); export const whiteLabelProjectSummaryDTO = z.object({accountCount: z.number().int().optional(), activeAccountCount: z.number().int().optional(), balance: z.number().optional(), blocked: z.boolean().optional(), created: z.string().optional(), customerCount: z.number().int().optional(), customers: z.array(customerSummaryDTO).optional(), dedicated: z.boolean().optional(), invoiceCount: z.number().int().optional(), invoices: z.array(invoiceSummaryDTO).optional(), outstandingAmount: z.number().optional(), ownerEmail: z.string().optional(), projectId: z.string().optional(), projectName: z.string().optional(), totalRevenue: z.number().optional()}); export const recentInvoiceDTO = z.object({amount: z.number().optional(), created: z.string().optional(), invoiceNumber: z.string().optional(), projectName: z.string().optional(), status: z.string().optional()}); export const recentActivityDTO = z.object({ownerEmail: z.string().optional(), projectId: z.string().optional(), projectName: z.string().optional(), timestamp: z.string().optional()}); export const whiteLabelDashboardDTO = z.object({currency: z.string().optional(), isTestStripeKey: z.boolean().optional(), manualCollection: z.boolean().optional(), projects: z.array(whiteLabelProjectSummaryDTO).optional(), recentInvoices: z.array(recentInvoiceDTO).optional(), recentProjects: z.array(recentActivityDTO).optional(), totalAccounts: z.number().int().optional(), totalActiveAccounts: z.number().int().optional(), totalCustomers: z.number().int().optional(), totalInvoices: z.number().int().optional(), totalManualOutstanding: z.number().optional(), totalOutstanding: z.number().optional(), totalPaidInvoices: z.number().int().optional(), totalProjects: z.number().int().optional(), totalRevenue: z.number().optional(), totalUnpaidInvoices: z.number().int().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 }; /** * Get WhiteLabel dashboard * * GET /rest/api/v1/projects/{projectId}/features/{featureId}/whitelabel/dashboard */ export const getApiRestApiV1ProjectsProjectIdFeaturesFeatureIdWhitelabelDashboard = async (args: GetApiRestApiV1ProjectsProjectIdFeaturesFeatureIdWhitelabelDashboardArgs, options?: GetApiRestApiV1ProjectsProjectIdFeaturesFeatureIdWhitelabelDashboardOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/features/${encodeURIComponent(String(args.featureId))}/whitelabel/dashboard${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(whiteLabelDashboardDTO, await res.json()) };