import {z} from 'zod' export type GetApiApiV10AppIdStorevalidationKioskArgs = {storeId: Array, page?: number | undefined, limit?: number | undefined, appId: string}; export type GetApiApiV10AppIdStorevalidationKioskOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const storeConfig = z.object({PickupEnabled: z.boolean().optional(), BankAccountAttached: z.boolean().optional(), MenuAssigned: z.boolean().optional(), HasFullAddress: z.boolean().optional(), PickupHours: z.boolean().optional(), IsPublished: z.boolean().optional()}); export const storeValidationConfig = z.object({StoreId: z.number().int().optional(), Name: z.string().optional(), IsValid: z.boolean().optional(), StoreGroupId: z.number().int().optional(), ConfigValidation: storeConfig.optional()}); export const restApiPaginationResultStoreValidationConfig = z.object({Page: z.number().int(), Limit: z.number().int(), TotalRecordCount: z.number().int(), Data: z.array(storeValidationConfig)}); 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 /api/v1.0/{appId}/storevalidation/kiosk */ export const getApiApiV10AppIdStorevalidationKiosk = async (args: GetApiApiV10AppIdStorevalidationKioskArgs, options?: GetApiApiV10AppIdStorevalidationKioskOptions) => { const {baseUrl = "https://api.flipdish.co", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.storeId ?? []) query.append("storeId", String(item)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1.0/${encodeURIComponent(String(args.appId))}/storevalidation/kiosk${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(restApiPaginationResultStoreValidationConfig, await res.json()) };