import {z} from 'zod' export type DBStringSlice = Array; export type NullTime = {Time?: string | undefined, Valid?: boolean | undefined}; export type IMap = unknown; export type TaxRate = {archived?: boolean | undefined, created?: string | undefined, description?: string | undefined, id?: number | undefined, marketplace?: boolean | undefined, name?: string | undefined, owner_id?: number | undefined, rate?: number | undefined, state?: string | undefined, updated?: string | undefined, zip_code?: string | undefined}; export type RentalItem = {applies_to_type?: DBStringSlice | undefined, available?: number | undefined, category?: string | undefined, category_id?: number | undefined, consigned_pay_pct?: number | undefined, created?: NullTime | undefined, daily?: boolean | undefined, deferred?: boolean | undefined, description?: string | undefined, hidden?: boolean | undefined, id?: number | undefined, image_url?: string | undefined, ledger_account_number?: number | undefined, location_id?: number | undefined, location_ids?: Array | undefined, maximum_price?: (number | null) | undefined, metadata?: IMap | undefined, minimum_price?: (number | null) | undefined, name?: string | undefined, percent?: number | undefined, percent_type?: string | undefined, position?: number | undefined, presentment_currency?: string | undefined, price?: number | undefined, rental_items_category_id?: (number | null) | undefined, rental_items_category_name?: string | undefined, rental_items_category_owner_name?: string | undefined, rental_items_category_reason?: string | undefined, rental_items_category_requested_name?: string | undefined, rental_items_category_status?: string | undefined, required?: boolean | undefined, settlement_currency?: string | undefined, tax?: number | undefined, tax_rate_id?: TaxRate | undefined, tax_rate_ids?: Array | undefined, travelers?: number | undefined, updated?: NullTime | undefined}; export type PatchApiItemsIdArgs = {id: number, body: RentalItem}; export type PatchApiItemsIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dBStringSlice = z.array(z.string()); export const nullTime = z.object({Time: z.string().optional(), Valid: z.boolean().optional()}); export const iMap = z.unknown(); export const taxRate = z.object({archived: z.boolean().optional(), created: z.string().optional(), description: z.string().optional(), id: z.number().int().optional(), marketplace: z.boolean().optional(), name: z.string().optional(), owner_id: z.number().int().optional(), rate: z.number().optional(), state: z.string().optional(), updated: z.string().optional(), zip_code: z.string().optional()}); export const rentalItem = z.object({applies_to_type: dBStringSlice.optional(), available: z.number().int().optional(), category: z.string().optional(), category_id: z.number().int().optional(), consigned_pay_pct: z.number().optional(), created: nullTime.optional(), daily: z.boolean().optional(), deferred: z.boolean().optional(), description: z.string().optional(), hidden: z.boolean().optional(), id: z.number().int().optional(), image_url: z.string().optional(), ledger_account_number: z.number().int().optional(), location_id: z.number().int().optional(), location_ids: z.array(z.number().int()).optional(), maximum_price: z.number().int().nullable().optional(), metadata: iMap.optional(), minimum_price: z.number().int().nullable().optional(), name: z.string().optional(), percent: z.number().optional(), percent_type: z.string().optional(), position: z.number().int().optional(), presentment_currency: z.string().optional(), price: z.number().int().optional(), rental_items_category_id: z.number().int().nullable().optional(), rental_items_category_name: z.string().optional(), rental_items_category_owner_name: z.string().optional(), rental_items_category_reason: z.string().optional(), rental_items_category_requested_name: z.string().optional(), rental_items_category_status: z.string().optional(), required: z.boolean().optional(), settlement_currency: z.string().optional(), tax: z.number().int().optional(), tax_rate_id: taxRate.optional(), tax_rate_ids: z.array(z.number().int()).optional(), travelers: z.number().int().optional(), updated: nullTime.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 }; /** * Creates a new item for a given rental * * PATCH /items/{id} * * Also accepts auth: API-Key */ export const patchApiItemsId = async (args: PatchApiItemsIdArgs, options: PatchApiItemsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/items/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(rentalItem, await res.json()) };