import {z} from 'zod' export type CreateApiAddSLArgs = {body: {data?: ({sellerId: string, name: string, reportsTo?: string | undefined, userGroupEdit?: (string | null) | undefined, userGroupViewDetails?: (string | null) | undefined}) | undefined, operation: string}}; export type CreateApiAddSLOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const seller = z.array(z.object({typedId: z.string().optional(), lastUpdateDate: z.string().optional(), sellerId: z.string().max(255).optional(), userGroupViewDetails: z.string().max(255).nullable().optional(), lastUpdateBy: z.number().int().optional(), userGroupEdit: z.string().max(255).nullable().optional(), createDate: z.string().optional(), version: z.number().int().optional(), createdBy: z.number().int().optional(), name: z.string().max(255).optional(), reportsTo: z.string().max(255).nullable().optional(), attribute19: z.string().max(255).nullable().optional(), attribute18: z.string().max(255).nullable().optional(), attribute17: z.string().max(255).nullable().optional(), attribute16: z.string().max(255).nullable().optional(), attribute15: z.string().max(255).nullable().optional(), attribute25: z.string().max(255).nullable().optional(), attribute24: z.string().max(255).nullable().optional(), attribute23: z.string().max(255).nullable().optional(), attribute22: z.string().max(255).nullable().optional(), attribute21: z.string().max(255).nullable().optional(), attribute20: z.string().max(255).nullable().optional(), attribute29: z.string().max(255).nullable().optional(), attribute28: z.string().max(255).nullable().optional(), attribute27: z.string().max(255).nullable().optional(), attribute26: z.string().max(255).nullable().optional(), attribute9: z.string().max(255).nullable().optional(), attribute8: z.string().max(255).nullable().optional(), attribute5: z.string().max(255).nullable().optional(), attribute4: z.string().max(255).nullable().optional(), attribute7: z.string().max(255).nullable().optional(), attribute6: z.string().max(255).nullable().optional(), attribute1: z.string().max(255).nullable().optional(), attribute14: z.string().max(255).nullable().optional(), attribute13: z.string().max(255).nullable().optional(), attribute3: z.string().max(255).nullable().optional(), attribute12: z.string().max(255).nullable().optional(), attribute2: z.string().max(255).nullable().optional(), attribute11: z.string().max(255).nullable().optional(), attribute10: z.string().max(255).nullable().optional(), attribute30: z.string().max(255).nullable().optional()})); export const createApiAddSLResponse = z.object({response: z.object({node: z.string().optional(), data: seller.optional(), status: z.number().int().optional()}).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 }; /** * Add a Seller * * POST /add/SL * * Also accepts auth: X-PriceFx-jwt */ export const createApiAddSL = async (args: CreateApiAddSLArgs, options?: CreateApiAddSLOptions) => { const {baseUrl = "https://companynode.pricefx.com/pricefx/companypartition", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/add/SL${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(createApiAddSLResponse, await res.json()) };