import {z} from 'zod' export type GetApiApiAppsAppIdGoogleAdsBillingInvoicesArgs = {app_id: string}; export type GetApiApiAppsAppIdGoogleAdsBillingInvoicesOptions = {baseUrl?: string | undefined, PersonalAccessTokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsInvoiceSummary = z.object({id: z.string(), invoice_date: z.string(), period_start: z.string(), period_end: z.string(), status: z.string(), currency_code: z.string(), ad_spend_micros: z.number().int(), service_fee_micros: z.number().int(), tax_micros: z.number().int(), total_micros: z.number().int(), is_refund: z.boolean(), signed_total_micros: z.number().int(), billing_type: z.string()}); export const getApiApiAppsAppIdGoogleAdsBillingInvoicesResponse = z.array(googleAdsInvoiceSummary); 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 }; /** * List Google Ads invoices * * GET /api/apps/{app_id}/google-ads/billing/invoices * * Also accepts auth: WorkspaceApiKeyAuth, WorkspaceApiKeyBearerAuth */ export const getApiApiAppsAppIdGoogleAdsBillingInvoices = async (args: GetApiApiAppsAppIdGoogleAdsBillingInvoicesArgs, options?: GetApiApiAppsAppIdGoogleAdsBillingInvoicesOptions) => { const {baseUrl = "https://app.base44.com", fetch: fetchFn = fetch, PersonalAccessTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (PersonalAccessTokenAuth !== undefined) headers.set('authorization', `Bearer ${PersonalAccessTokenAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/apps/${encodeURIComponent(String(args.app_id))}/google-ads/billing/invoices${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(getApiApiAppsAppIdGoogleAdsBillingInvoicesResponse, await res.json()) };