import {z} from 'zod' export type UpdateApiV2BillingAgreementsIdArgs = {id: number, body: {name: string, description?: string | undefined, products?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, deviceCountsProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, softwareLicenseProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, backupStorageCountsProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, timeEntriesProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, endUserCountsProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, content?: ({startDate: string, endDate: string, businessHours?: ({twentyFourSeven?: boolean | undefined, days?: (Array<{day?: ('MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY') | undefined, startHour?: number | undefined, endHour?: number | undefined, allDayClosed?: boolean | undefined}>) | undefined}) | undefined, interval?: ('ANNUAL' | 'SEMIANNUAL' | 'QUARTERLY' | 'MONTHLY' | 'BIMONTHLY' | 'BIWEEKLY' | 'WEEKLY' | 'ONE_TIME') | undefined, billDate?: string | undefined}) | undefined, clientId?: number | undefined, invoiceGenerationType?: ('AUTOMATIC' | 'MANUAL' | 'ONE_OFF') | undefined, multiMatchDevices?: boolean | undefined, multiMatchDeviceBackups?: boolean | undefined, multiMatchEndUsers: boolean, billEmails?: Array | undefined, billCcEmails?: Array | undefined, billBccEmails?: Array | undefined, businessHoursSource?: ('CUSTOM' | 'TICKETING') | undefined, nextBillDate?: string | undefined, nextBillingPeriodStartDate?: string | undefined, displayIncludedTimeOnInvoices: boolean, dueDaysSource?: ('CUSTOM' | 'INHERIT_FROM_CONFIGURATION') | undefined, dueDays?: number | undefined, ticketBillingSettings?: ({billTicketInAnyStatus: boolean, condition?: ({operator: 'in' | 'not_in' | 'parent_in' | 'parent_not_in', value: string}) | undefined}) | undefined, autoApproveInvoice: boolean, autoCompleteInvoice: boolean, taxId?: number | undefined, quickBooks?: ({externalTax?: {id: string, name: string} | undefined, allowOnlineCreditCardPayments: boolean, allowOnlineAchPayments: boolean, externalTaxRequest?: {id: string, name: string} | undefined} | null) | undefined, xero?: ({externalTax?: {id: string, name: string} | undefined, taxlessItemsExternalTax?: {id: string, name: string} | undefined, brandingTheme?: {id: string, name: string} | undefined, newInvoiceStatus?: ('DRAFT' | 'SUBMITTED' | 'AUTHORISED') | undefined, externalTaxRequest?: {id: string, name: string} | undefined, taxlessItemsExternalTaxRequest?: {id: string, name: string} | undefined, brandingThemeRequest?: {id: string, name: string} | undefined} | null) | undefined, managedDeviceProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, managedDeviceBackupProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, laborTicketTimeEntryProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, managedEndUserProducts?: (Array<{id?: number | undefined, name: string, description: string, quantityType: 'MANUAL' | 'DEVICE_COUNTS' | 'TIME_ENTRIES' | 'END_USER_COUNTS' | 'BACKUP_STORAGE_COUNTS' | 'SOFTWARE_LICENSE', content?: {[key: string]: unknown} | undefined, integrationSettings?: {[key: string]: unknown} | undefined, productId?: number | undefined, order?: number | undefined, accountId: number, group: boolean, productUserRole?: ({allowAllTechnicians: boolean, userRoles: Array} | null) | undefined, taxId?: number | undefined, inheritTaxFromAgreement?: boolean | undefined}>) | undefined, invoiceNote: string, quickBooksAgreementIntegrationDataRequest?: ({externalTax?: {id: string, name: string} | undefined, allowOnlineCreditCardPayments: boolean, allowOnlineAchPayments: boolean, externalTaxRequest?: {id: string, name: string} | undefined} | null) | undefined, xeroAgreementIntegrationDataRequest?: ({externalTax?: {id: string, name: string} | undefined, taxlessItemsExternalTax?: {id: string, name: string} | undefined, brandingTheme?: {id: string, name: string} | undefined, newInvoiceStatus?: ('DRAFT' | 'SUBMITTED' | 'AUTHORISED') | undefined, externalTaxRequest?: {id: string, name: string} | undefined, taxlessItemsExternalTaxRequest?: {id: string, name: string} | undefined, brandingThemeRequest?: {id: string, name: string} | undefined} | null) | undefined, multiMatchSoftwareLicenses?: boolean | undefined}}; export type UpdateApiV2BillingAgreementsIdOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2BillingAgreementsIdResponse = z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().nullable().optional(), invoiceGenerationType: z.enum(["AUTOMATIC", "MANUAL", "ONE_OFF"]).optional(), lastBillDate: z.number().nullable().optional(), nextBillDate: z.string().nullable().optional(), nextBillingPeriodStartDate: z.string().nullable().optional(), lastPeriodStartDate: z.string().nullable().optional(), lastPeriodEndDate: z.string().nullable().optional(), content: z.object({interval: z.string().nullable().optional(), billDate: z.string().nullable().optional(), startDate: z.string().optional(), endDate: z.string().nullable().optional(), businessHours: z.object({twentyFourSeven: z.boolean().optional(), days: z.array(z.object({day: z.enum(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]).optional(), startHour: z.number().int().gte(0).lte(86399).optional(), endHour: z.number().int().gte(0).lte(86399).optional(), allDayClosed: z.boolean().optional()})).optional()}).optional()}).optional(), contact: z.object({uid: z.string().optional(), id: z.number().int().optional(), clientId: z.number().int().nullable().optional(), clientName: z.string().nullable().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().optional(), deleted: z.boolean().optional(), userType: z.enum(["TECHNICIAN", "END_USER", "CONTACT"]).optional(), enabled: z.boolean().optional(), ninjaAdmin: z.boolean().optional(), sysadmin: z.boolean().optional()}).nullable().optional(), taxRate: z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().nullable().optional(), taxRate: z.number().optional()}).nullable().optional(), client: z.object({id: z.number().int().optional(), name: z.string().optional(), deleted: z.boolean()}).optional(), externalTax: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), createTime: z.number().optional(), updateTime: z.number().optional(), timeDefault: z.boolean().optional(), businessHoursSource: z.enum(["CUSTOM", "TICKETING"]).optional(), dueDaysSource: z.enum(["CUSTOM", "INHERIT_FROM_CONFIGURATION"]).optional(), dueDays: z.number().int().optional(), allowOnlineCreditCardPayments: z.boolean().optional(), allowOnlineAchPayments: z.boolean().optional(), invoiceNote: z.string().optional(), billEmails: z.array(z.string()).optional(), billCcEmails: z.array(z.string()).optional(), billBccEmails: z.array(z.string()).optional(), ticketBillingSettings: z.object({billTicketInAnyStatus: z.boolean().optional(), condition: z.object({operator: z.string().optional(), value: z.string().optional(), metadata: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()}).nullable()).nullable().optional()}).nullable().optional()}).nullable().optional(), multiMatchEndUsers: z.boolean().optional(), multiMatchDevices: z.boolean().optional(), products: z.array(z.object({id: z.number().int().optional(), productId: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), quantityType: z.enum(["MANUAL", "DEVICE_COUNTS", "TIME_ENTRIES", "END_USER_COUNTS", "BACKUP_STORAGE_COUNTS", "SOFTWARE_LICENSE"]).optional(), content: z.record(z.string(), z.unknown()).optional(), order: z.number().int().optional(), productUserRole: z.object({allowAllTechnicians: z.boolean().optional(), userRoles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional()}).optional(), integrationSettings: z.record(z.string(), z.unknown()).optional(), accountId: z.number().int().optional(), group: z.boolean().optional(), taxId: z.number().int().optional(), inheritTaxFromAgreement: z.boolean().optional()}).nullable()).nullable().optional(), deviceCountsProducts: z.array(z.object({id: z.number().int().optional(), productId: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), quantityType: z.enum(["MANUAL", "DEVICE_COUNTS", "TIME_ENTRIES", "END_USER_COUNTS", "BACKUP_STORAGE_COUNTS", "SOFTWARE_LICENSE"]).optional(), content: z.record(z.string(), z.unknown()).optional(), order: z.number().int().optional(), productUserRole: z.object({allowAllTechnicians: z.boolean().optional(), userRoles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional()}).optional(), integrationSettings: z.record(z.string(), z.unknown()).optional(), accountId: z.number().int().optional(), group: z.boolean().optional(), taxId: z.number().int().optional(), inheritTaxFromAgreement: z.boolean().optional()}).nullable()).nullable().optional(), timeEntriesProducts: z.array(z.object({id: z.number().int().optional(), productId: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), quantityType: z.enum(["MANUAL", "DEVICE_COUNTS", "TIME_ENTRIES", "END_USER_COUNTS", "BACKUP_STORAGE_COUNTS", "SOFTWARE_LICENSE"]).optional(), content: z.record(z.string(), z.unknown()).optional(), order: z.number().int().optional(), productUserRole: z.object({allowAllTechnicians: z.boolean().optional(), userRoles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional()}).optional(), integrationSettings: z.record(z.string(), z.unknown()).optional(), accountId: z.number().int().optional(), group: z.boolean().optional(), taxId: z.number().int().optional(), inheritTaxFromAgreement: z.boolean().optional()}).nullable()).nullable().optional(), endUserCountsProducts: z.array(z.object({id: z.number().int().optional(), productId: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), quantityType: z.enum(["MANUAL", "DEVICE_COUNTS", "TIME_ENTRIES", "END_USER_COUNTS", "BACKUP_STORAGE_COUNTS", "SOFTWARE_LICENSE"]).optional(), content: z.record(z.string(), z.unknown()).optional(), order: z.number().int().optional(), productUserRole: z.object({allowAllTechnicians: z.boolean().optional(), userRoles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional()}).optional(), integrationSettings: z.record(z.string(), z.unknown()).optional(), accountId: z.number().int().optional(), group: z.boolean().optional(), taxId: z.number().int().optional(), inheritTaxFromAgreement: z.boolean().optional()}).nullable()).nullable().optional(), backupStorageCountsProducts: z.array(z.object({id: z.number().int().optional(), productId: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), quantityType: z.enum(["MANUAL", "DEVICE_COUNTS", "TIME_ENTRIES", "END_USER_COUNTS", "BACKUP_STORAGE_COUNTS", "SOFTWARE_LICENSE"]).optional(), content: z.record(z.string(), z.unknown()).optional(), order: z.number().int().optional(), productUserRole: z.object({allowAllTechnicians: z.boolean().optional(), userRoles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional()}).optional(), integrationSettings: z.record(z.string(), z.unknown()).optional(), accountId: z.number().int().optional(), group: z.boolean().optional(), taxId: z.number().int().optional(), inheritTaxFromAgreement: z.boolean().optional()}).nullable()).nullable().optional(), softwareLicenseProducts: z.array(z.object({id: z.number().int().optional(), productId: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), quantityType: z.enum(["MANUAL", "DEVICE_COUNTS", "TIME_ENTRIES", "END_USER_COUNTS", "BACKUP_STORAGE_COUNTS", "SOFTWARE_LICENSE"]).optional(), content: z.record(z.string(), z.unknown()).optional(), order: z.number().int().optional(), productUserRole: z.object({allowAllTechnicians: z.boolean().optional(), userRoles: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional()}).optional(), integrationSettings: z.record(z.string(), z.unknown()).optional(), accountId: z.number().int().optional(), group: z.boolean().optional(), taxId: z.number().int().optional(), inheritTaxFromAgreement: z.boolean().optional()}).nullable()).nullable().optional(), multiMatchDeviceBackups: z.boolean().optional(), displayIncludedTimeOnInvoices: z.boolean().optional(), taxId: z.number().int().optional(), autoApproveInvoice: z.boolean().optional(), autoCompleteInvoice: z.boolean().optional(), quickBooks: z.object({externalTax: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), allowOnlineCreditCardPayments: z.boolean().optional(), allowOnlineAchPayments: z.boolean().optional()}).optional(), xero: z.object({externalTax: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), brandingTheme: z.object({id: z.string().optional(), name: z.string().optional()}).nullable().optional(), taxlessItemsExternalTax: z.object({id: z.string().optional(), name: z.string().optional()}).nullable().optional(), newInvoiceStatus: z.enum(["DRAFT", "SUBMITTED", "AUTHORISED"]).optional()}).optional(), archived: z.boolean().optional(), active: z.boolean().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 }; /** * Updates an agreement. * * PUT /v2/billing/agreements/{id} * * Also accepts auth: sessionKey */ export const updateApiV2BillingAgreementsId = async (args: UpdateApiV2BillingAgreementsIdArgs, options: UpdateApiV2BillingAgreementsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/billing/agreements/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiV2BillingAgreementsIdResponse, await res.json()) };