import {z} from 'zod' export type Limitation = {Count: number, Cursor?: (string | null) | undefined}; export type TimeFilterInterval = {StartUtc?: (string | null) | undefined, EndUtc?: (string | null) | undefined}; export type ActivityStates = 'Deleted' | 'Active'; export type CashierParameters = {ClientToken: string, AccessToken: string, Client: string, Limitation: Limitation, EnterpriseIds?: (Array | null) | undefined, Ids?: (Array | null) | undefined, UpdatedUtc?: (TimeFilterInterval | null) | undefined, ActivityStates?: (Array | null) | undefined}; export type CreateApiApiConnectorV1CashiersGetAllArgs = {body: CashierParameters}; export type CreateApiApiConnectorV1CashiersGetAllOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const cashier = z.object({Id: z.string(), EnterpriseId: z.string(), IsActive: z.boolean(), Name: z.string().min(1), CreatedUtc: z.string().min(1), UpdatedUtc: z.string().min(1)}); export const cashierResult = z.object({Cashiers: z.array(cashier), Cursor: z.string().nullable().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 all cashiers * * POST /api/connector/v1/cashiers/getAll */ export const createApiApiConnectorV1CashiersGetAll = async (args: CreateApiApiConnectorV1CashiersGetAllArgs, options?: CreateApiApiConnectorV1CashiersGetAllOptions) => { const {baseUrl = "https://api.mews.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/connector/v1/cashiers/getAll${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(cashierResult, await res.json()) };