import {z} from 'zod' export type PagingPageNumber = number; export type PagingPageSize = number; export type GetApiResellerEventDataArgs = {resellerId?: string | undefined, pageNumber?: PagingPageNumber | undefined, pageSize?: PagingPageSize | undefined}; export type GetApiResellerEventDataOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const resellerEventData = z.object({resellerId: z.string().optional(), merchantRegistrationNumber: z.string(), eventId: z.string(), eventOrganizerId: z.string(), eventRevenueSharePercentage: z.number(), merchantLegalName: z.string().optional(), merchantVatNumber: z.string().optional(), servicePackage: z.string().optional(), eventExpiryDate: z.string().optional(), createdUserUid: z.string().optional(), createdBy: z.string().optional(), createdDate: z.string().optional(), modifiedUserUid: z.string().optional(), modifiedBy: z.string().optional(), modifiedDate: z.string().optional()}); export const resellerEventDataPageResponse = z.object({content: z.array(resellerEventData).optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), currentPage: z.number().int().optional(), size: z.number().int().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 }; /** * List reseller event data records * * GET /reseller-event-data * * Also accepts auth: BearerAuth */ export const getApiResellerEventData = async (args: GetApiResellerEventDataArgs, options?: GetApiResellerEventDataOptions) => { const {baseUrl = "https://emea.gsc.verifone.cloud/oidc/checkout-service", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.resellerId != null) query.append("resellerId", String(args.resellerId)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/reseller-event-data${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(resellerEventDataPageResponse, await res.json()) };