import {z} from 'zod' export type GetApiAppResellerV1OrdersArgs = {context: 'RESELLER, RESELLER_MANAGER', number?: number | undefined, size?: number | undefined, sort?: string | undefined, userId?: string | undefined, resellerCompanyId: string, customerCompanyId: string, createdOn?: string | undefined, status?: string | undefined, paidStatus?: 'PAID, FREE' | undefined, pending?: boolean | undefined, searchText?: string | undefined}; export type GetApiAppResellerV1OrdersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pageMetadata = z.object({number: z.number(), size: z.number(), totalElements: z.number(), totalPages: z.number()}); export const companyAssociation = z.object({id: z.string(), name: z.string()}); export const orderPagedReadItem = z.object({id: z.string(), createdOn: z.number(), status: z.string(), frequency: z.string(), totalFee: z.string(), editionName: z.string(), orderCartId: z.string().optional(), applicationName: z.string(), company: companyAssociation}); export const orderPagedReadResponse = z.object({page: pageMetadata, content: z.array(orderPagedReadItem)}); 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 orders * * GET /appReseller/v1/orders */ export const getApiAppResellerV1Orders = async (args: GetApiAppResellerV1OrdersArgs, options?: GetApiAppResellerV1OrdersOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.context != null) query.append("context", String(args.context)) if (args.number != null) query.append("number", String(args.number)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.resellerCompanyId != null) query.append("resellerCompanyId", String(args.resellerCompanyId)) if (args.customerCompanyId != null) query.append("customerCompanyId", String(args.customerCompanyId)) if (args.createdOn != null) query.append("createdOn", String(args.createdOn)) if (args.status != null) query.append("status", String(args.status)) if (args.paidStatus != null) query.append("paidStatus", String(args.paidStatus)) if (args.pending != null) query.append("pending", String(args.pending)) if (args.searchText != null) query.append("searchText", String(args.searchText)) const url = `${baseUrl.replace(/\/+$/, '')}/appReseller/v1/orders${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(orderPagedReadResponse, await res.json()) };