import {z} from 'zod' export type PriceType = 0 | 1; export type PriceRowStatus = 0 | 1 | 2; export type GetApiV1ItemsPricesBaseDownloadXlsxArgs = {type: PriceType, AsOf: string, status?: Array | undefined, Account: unknown}; export type GetApiV1ItemsPricesBaseDownloadXlsxOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ItemsPricesBaseDownloadXlsxResponse = z.string(); 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 }; /** * Download every item's base price as an xlsx — the catalogue-wide base sheet, and the round-trip * template for M:IO.CommonAPI.Controllers.v1.Catalog.ItemPricesController.BulkUpsertBasePrices(IO.Domain.Shared.Enums.PriceType,System.Collections.Generic.List{IO.Catalog.Contracts.DTO.Pricelists.BasePriceSheetRow},System.Threading.CancellationToken). Columns are itemCode, price, quantity, fromDate, * endDate; the price type comes from `type` and every emitted row is a * `relation=Item, relationId=0` row. * *
Tenant-primary only, matching the import rather than the two sibling exports. This sheet * exists to be edited and posted back, so a caller who could fetch it but not import it would hold a file * they cannot use. R1 still applies underneath: a purchase sheet omits rows on items the caller does not * own — though for a tenant-primary caller that is every item.
Answers `204` when nothing is exportable, `202` with a job id above * IO.Admin.BulkExportOptions.SyncRowThreshold, and takes no row filter — the base sheet pins no axis, * so it offers none (see IO.Catalog.Contracts.DTO.Pricelists.BasePricesExportRequest). * * GET /v1/Items/prices/base/download/xlsx */ export const getApiV1ItemsPricesBaseDownloadXlsx = async (args: GetApiV1ItemsPricesBaseDownloadXlsxArgs, options: GetApiV1ItemsPricesBaseDownloadXlsxOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = 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.AsOf != null) query.append("AsOf", String(args.AsOf)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.Account != null) query.append("Account", String(args.Account)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Items/prices/base/download/xlsx${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(getApiV1ItemsPricesBaseDownloadXlsxResponse, await res.json()) };