import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdInventorytransactionArgs = {businessId: string, branchId: string, type?: string | undefined, deleted?: boolean | undefined, compensatingTransaction?: boolean | undefined, updated_from?: string | undefined, updated_to?: string | undefined, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdInventorytransactionOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const inventoryTransaction = z.object({id: z.string().optional(), inventoryId: z.string().optional(), transactionDateTime: z.string().optional(), quantityChange: z.number().optional(), type: z.string().optional(), relatedTransactionDateTime: z.string().optional(), relatedTransactionDeleted: z.boolean().optional(), compensatingTransaction: z.boolean().optional(), purchaseItemId: z.string().optional(), stockTakeItemId: z.string().optional(), deleted: z.boolean().optional()}); export const pageMetadata = z.object({size: z.number().int().optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), number: z.number().int().optional()}); export const dataPagedModelInventoryTransaction = z.object({_embedded: z.object({inventoryTransactions: z.array(inventoryTransaction).optional()}).optional(), page: pageMetadata.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 }; /** * List inventory transactions * * GET /api/business/{businessId}/branch/{branchId}/inventorytransaction */ export const getApiApiBusinessBusinessIdBranchBranchIdInventorytransaction = async (args: GetApiApiBusinessBusinessIdBranchBranchIdInventorytransactionArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdInventorytransactionOptions) => { const {baseUrl = "http://api-gateway-eu.phorest.com/third-party-api-server", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.compensatingTransaction != null) query.append("compensatingTransaction", String(args.compensatingTransaction)) if (args.updated_from != null) query.append("updated_from", String(args.updated_from)) if (args.updated_to != null) query.append("updated_to", String(args.updated_to)) if (args.size != null) query.append("size", String(args.size)) if (args.page != null) query.append("page", String(args.page)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/business/${encodeURIComponent(String(args.businessId))}/branch/${encodeURIComponent(String(args.branchId))}/inventorytransaction${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(dataPagedModelInventoryTransaction, await res.json()) };