import {z} from 'zod' export type GetApiV23CustomersCustomersIdInvoicesArgs = {customersId: string, billingSetup?: string | undefined, includeGranularLevelInvoiceDetails?: boolean | undefined, issueMonth?: ('UNSPECIFIED' | 'UNKNOWN' | 'JANUARY' | 'FEBRUARY' | 'MARCH' | 'APRIL' | 'MAY' | 'JUNE' | 'JULY' | 'AUGUST' | 'SEPTEMBER' | 'OCTOBER' | 'NOVEMBER' | 'DECEMBER') | undefined, issueYear?: string | undefined}; export type GetApiV23CustomersCustomersIdInvoicesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23CommonDateRange = z.object({endDate: z.string().optional(), startDate: z.string().optional()}); export const googleAdsSearchads360V23ResourcesInvoiceCampaignSummary = z.object({amountMicros: z.string().optional(), campaignDescription: z.string().optional(), quantity: z.string().optional(), unitOfMeasure: z.enum(["UNSPECIFIED", "UNKNOWN", "CLICKS", "IMPRESSIONS", "ACQUISITIONS", "PHONE_CALLS", "VIDEO_PLAYS", "DAYS", "AUDIO_PLAYS", "ENGAGEMENTS", "SECONDS", "LEADS", "GUEST_STAYS", "HOURS"]).optional()}); export const googleAdsSearchads360V23ResourcesInvoiceInvalidActivitySummary = z.object({amountMicros: z.string().optional(), originalAccountBudgetName: z.string().optional(), originalInvoiceId: z.string().optional(), originalMonthOfService: z.enum(["UNSPECIFIED", "UNKNOWN", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]).optional(), originalPurchaseOrderNumber: z.string().optional(), originalYearOfService: z.string().optional()}); export const googleAdsSearchads360V23ResourcesInvoiceAccountBudgetSummary = z.object({accountBudget: z.string().optional(), accountBudgetName: z.string().optional(), billableActivityDateRange: googleAdsSearchads360V23CommonDateRange.optional(), billedAmountMicros: z.string().optional(), campaignSummaries: z.array(googleAdsSearchads360V23ResourcesInvoiceCampaignSummary).optional(), customer: z.string().optional(), customerDescriptiveName: z.string().optional(), invalidActivityAmountMicros: z.string().optional(), invalidActivitySummaries: z.array(googleAdsSearchads360V23ResourcesInvoiceInvalidActivitySummary).optional(), overdeliveryAmountMicros: z.string().optional(), purchaseOrderNumber: z.string().optional(), servedAmountMicros: z.string().optional(), subtotalAmountMicros: z.string().optional(), taxAmountMicros: z.string().optional(), totalAmountMicros: z.string().optional()}); export const googleAdsSearchads360V23ResourcesInvoiceAdjustmentSummary = z.object({adjustmentDescription: z.string().optional(), amountMicros: z.string().optional()}); export const googleAdsSearchads360V23ResourcesInvoiceRegulatoryCostSummary = z.object({amountMicros: z.string().optional(), regulatoryFeeType: z.enum(["UNSPECIFIED", "UNKNOWN", "AUSTRIA_DST_FEE", "TURKIYE_REGULATORY_OPERATING_COST", "UK_DST_FEE", "SPAIN_REGULATORY_OPERATING_COST", "FRANCE_REGULATORY_OPERATING_COST", "ITALY_REGULATORY_OPERATING_COST", "INDIA_REGULATORY_OPERATING_COST", "POLAND_REGULATORY_OPERATING_COST", "OPERATING_CHARGES", "CANADA_DST_FEE"]).optional()}); export const googleAdsSearchads360V23ResourcesInvoiceAccountSummary = z.object({adjustmentSummaries: z.array(googleAdsSearchads360V23ResourcesInvoiceAdjustmentSummary).optional(), billingCorrectionSubtotalAmountMicros: z.string().optional(), billingCorrectionTaxAmountMicros: z.string().optional(), billingCorrectionTotalAmountMicros: z.string().optional(), couponAdjustmentSubtotalAmountMicros: z.string().optional(), couponAdjustmentTaxAmountMicros: z.string().optional(), couponAdjustmentTotalAmountMicros: z.string().optional(), customer: z.string().optional(), excessCreditAdjustmentSubtotalAmountMicros: z.string().optional(), excessCreditAdjustmentTaxAmountMicros: z.string().optional(), excessCreditAdjustmentTotalAmountMicros: z.string().optional(), exportChargeSubtotalAmountMicros: z.string().optional(), exportChargeTaxAmountMicros: z.string().optional(), exportChargeTotalAmountMicros: z.string().optional(), regulatoryCostSummaries: z.array(googleAdsSearchads360V23ResourcesInvoiceRegulatoryCostSummary).optional(), regulatoryCostsSubtotalAmountMicros: z.string().optional(), regulatoryCostsTaxAmountMicros: z.string().optional(), regulatoryCostsTotalAmountMicros: z.string().optional(), subtotalAmountMicros: z.string().optional(), taxAmountMicros: z.string().optional(), totalAmountMicros: z.string().optional()}); export const googleAdsSearchads360V23ResourcesInvoice = z.object({accountBudgetSummaries: z.array(googleAdsSearchads360V23ResourcesInvoiceAccountBudgetSummary).optional(), accountSummaries: z.array(googleAdsSearchads360V23ResourcesInvoiceAccountSummary).optional(), adjustmentsSubtotalAmountMicros: z.string().optional(), adjustmentsTaxAmountMicros: z.string().optional(), adjustmentsTotalAmountMicros: z.string().optional(), billingSetup: z.string().optional(), correctedInvoice: z.string().optional(), currencyCode: z.string().optional(), dueDate: z.string().optional(), exportChargeSubtotalAmountMicros: z.string().optional(), exportChargeTaxAmountMicros: z.string().optional(), exportChargeTotalAmountMicros: z.string().optional(), id: z.string().optional(), issueDate: z.string().optional(), paymentsAccountId: z.string().optional(), paymentsProfileId: z.string().optional(), pdfUrl: z.string().optional(), regulatoryCostsSubtotalAmountMicros: z.string().optional(), regulatoryCostsTaxAmountMicros: z.string().optional(), regulatoryCostsTotalAmountMicros: z.string().optional(), replacedInvoices: z.array(z.string()).optional(), resourceName: z.string().optional(), serviceDateRange: googleAdsSearchads360V23CommonDateRange.optional(), subtotalAmountMicros: z.string().optional(), taxAmountMicros: z.string().optional(), totalAmountMicros: z.string().optional(), type: z.enum(["UNSPECIFIED", "UNKNOWN", "CREDIT_MEMO", "INVOICE"]).optional()}); export const googleAdsSearchads360V23ServicesListInvoicesResponse = z.object({invoices: z.array(googleAdsSearchads360V23ResourcesInvoice).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 }; /** * Returns all invoices associated with a billing setup, for a given month. List of thrown errors: [AuthenticationError]() [AuthorizationError]() [FieldError]() [HeaderError]() [InternalError]() [InvoiceError]() [QuotaError]() [RequestError]() * * GET /v23/customers/{customersId}/invoices */ export const getApiV23CustomersCustomersIdInvoices = async (args: GetApiV23CustomersCustomersIdInvoicesArgs, options?: GetApiV23CustomersCustomersIdInvoicesOptions) => { const {baseUrl = "https://searchads360.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.billingSetup != null) query.append("billingSetup", String(args.billingSetup)) if (args.includeGranularLevelInvoiceDetails != null) query.append("includeGranularLevelInvoiceDetails", String(args.includeGranularLevelInvoiceDetails)) if (args.issueMonth != null) query.append("issueMonth", String(args.issueMonth)) if (args.issueYear != null) query.append("issueYear", String(args.issueYear)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v23/customers/${encodeURIComponent(String(args.customersId))}/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(googleAdsSearchads360V23ServicesListInvoicesResponse, await res.json()) };