import {z} from 'zod' export type GetApiSellersIdArgs = {id: number}; export type GetApiSellersIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const sellerAddress = z.object({name: z.string().max(50), phone: z.string().max(30), email: z.string().max(80), zip: z.string().max(29).optional(), city: z.string().max(30), state: z.string().optional(), countryIso2: z.string(), street: z.string().max(50).optional(), street2: z.string().max(50).optional()}); export const link = z.object({link: z.string().optional()}); export const sellerGet = z.object({name: z.string().optional(), usesWarehouseSku: z.boolean().optional(), warehouseId: z.number().int().optional(), companyName: z.string().max(50).optional(), sendToEmail: z.string().max(80), sellerServices: z.array(z.string()).optional(), pixiSellerIdentifier: z.string().max(5).optional(), pixiArticlePrefix: z.string().max(10).optional(), pixiManualOrderPrefix: z.string().max(10).optional(), allowInboundOverReceiving: z.boolean().optional(), allowReturnOverReceiving: z.boolean().optional(), lottableIdRequired: z.boolean().optional(), sendToCcEmail: z.string().max(80).optional(), voecNumber: z.string().max(20).optional(), vatNumber: z.string().max(20).optional(), vatNumberRequired: z.boolean().optional(), homePage: z.string().max(80).optional(), useArticleBaseData: z.boolean().optional(), eoriNumber: z.string().max(35).optional(), sellerAddress: sellerAddress, vatNumberPerCountry: z.record(z.string(), z.string()).optional(), eoriNumberPerCountry: z.record(z.string(), z.string()).optional(), subscriptionPackage: z.enum(["RISING_STAR", "STELLAR_EXPLORER", "FULFILLED_LEGEND", "WITHOUT_PACKAGE", "SEND_IT_YOURSELF", "CUSTOMIZED"]), sellerLogo: link.optional(), exportedAt: z.string().optional(), connectorApiKey: z.string().optional(), managingGroup: z.enum(["QUIVO", "GWC"]).optional(), trackingEnabled: z.boolean().optional(), dimensionsRequired: z.boolean().optional(), customAttributes: z.record(z.string(), z.string()).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 }; /** * Get seller by sellerId * * GET /sellers/{id} */ export const getApiSellersId = async (args: GetApiSellersIdArgs, options?: GetApiSellersIdOptions) => { const {baseUrl = "https://api.quivo.co", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/sellers/${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(sellerGet, await res.json()) };