import {z} from 'zod' export type PriceType = 0 | 1; export type BasePriceSheetRow = {itemCode?: (string | null) | undefined, price?: number | undefined, quantity?: number | undefined, fromDate?: string | undefined, endDate?: (string | null) | undefined}; export type CreateApiV1ItemsPricesBaseBulkArgs = {type: PriceType, Account: unknown, body: Array}; export type CreateApiV1ItemsPricesBaseBulkOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1ItemsPricesBaseBulkResponse = z.number().int(); 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 }; /** * Bulk-upsert item base prices from the base price sheet — every item's own company-agnostic * price, across the whole catalogue. Each row's `itemCode` selects the item and every row is * written as `relation=Item, relationId=0`; the price type comes from `type`. Returns the * count upserted. * *
Tenant-primary only, and that is the substantive difference from the other two bulk * imports rather than an incidental one. A base price is what every company without an override of its * own resolves to, so writing them across the catalogue is a tenant-level act, not an ownership-scoped * one — there is no R2 ownership branch on this endpoint because the primary gate subsumes it. Checked * here, before M:IO.Admin.BulkExportOptionsExtensions.RouteImport(IO.Admin.BulkExportOptions,System.Int32), so the inline and queued paths are * covered by one statement; re-checked in the handler and in the worker's validation, the same * belt-and-braces the `PRICELISTS` feature gate gets.
Deliberately stricter than `POST /v1/Items/{itemId}/prices/bulk`, where a non-primary owner * may still write their own item's base row via an empty `companyCode`. One item at a time is an * ownership act; the whole catalogue is not.
The third sheet, and the only one that pins neither axis by route — which is why the queued * job needs an explicit IO.Domain.Shared.Enums.PriceSheetScope rather than inferring the sheet from whichever * id the config carries.
Import only. There is deliberately no matching export: the other two sheets are a round * trip and their export doubles as the template, whereas this one ships a static template. Note base * prices are already readable per item — `GET /v1/Items/{itemId}/prices` returns the base row * whenever `relationId` is omitted, and the item sheet exports it with an empty * `companyCode` — so what is missing is only the catalogue-wide axis this endpoint writes on. * * POST /v1/Items/prices/base/bulk */ export const createApiV1ItemsPricesBaseBulk = async (args: CreateApiV1ItemsPricesBaseBulkArgs, options: CreateApiV1ItemsPricesBaseBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json-patch+json; x-api-version=1.0") headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) 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/bulk${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV1ItemsPricesBaseBulkResponse, await res.json()) };