import {z} from 'zod' export type GetApiInventoryJournalEntriesIdArgs = {id: string}; export type GetApiInventoryJournalEntriesIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, accountToken?: string | undefined, fetch?: typeof fetch | undefined}; export const id = z.number().int().gte(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const inventoryJournalEntry = z.object({id: id, created_at: createdAt.optional(), updated_at: updatedAt.optional(), account_id: id, user_id: z.number().int(), part_id: z.number().int(), part: z.object({number: z.string().optional(), id: id.optional()}), part_location_detail_id: z.number().int(), part_location: z.object({name: z.string().optional(), id: id.optional()}), previous_quantity: z.string(), current_quantity: z.string(), adjustment_quantity: z.string(), work_order: z.object({number: z.string().optional(), id: id.optional()}).nullable(), work_order_part_line_item_id: z.number().int().nullable(), inventory_adjustment_reason_id: z.number().int().nullable(), inventory_adjustment_reason: z.object({name: z.string().optional()}).nullable(), comments_count: z.number().int(), adjustment_type: z.enum(["initial", "manual", "work_order", "purchase_order", "bulk_update", "transfer", "inspection_submission", "inspection_shortfall"]), transfer_part_location_id: z.number().int().nullable(), purchase_order: z.object({number: z.string().optional(), id: id.optional()}).nullable(), purchase_order_line_item_id: z.number().int().nullable(), work_order_id: z.number().int().nullable(), vendor_id: z.number().int().nullable(), vendor: z.object({name: z.string().optional(), id: id.optional()}).nullable(), user: z.object({email: z.string().optional()})}).nullable(); 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 }; /** * Retrieve Inventory Journal Entry * * GET /inventory_journal_entries/{id} */ export const getApiInventoryJournalEntriesId = async (args: GetApiInventoryJournalEntriesIdArgs, options?: GetApiInventoryJournalEntriesIdOptions) => { const {baseUrl = "https://secure.fleetio.com/api", fetch: fetchFn = fetch, apiKey, accountToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) if (accountToken !== undefined) headers.set("Account-Token", accountToken) const url = `${baseUrl.replace(/\/+$/, '')}/inventory_journal_entries/${encodeURIComponent(String(args.id))}${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(inventoryJournalEntry, await res.json()) };