import {z} from 'zod' export type GetApiApiShopsDocumentsArgs = {shop_ids?: string | undefined, include_deleted?: boolean | undefined, updated_since?: string | undefined}; export type GetApiApiShopsDocumentsOptions = {baseUrl?: string | undefined, FrontBearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const s30Response200ShopDocuments = z.object({date_deleted: z.string().optional(), date_uploaded: z.string().optional(), file_name: z.string(), id: z.number().int(), shop_id: z.number().int(), type: z.string()}); export const s30Response200 = z.object({shop_documents: z.array(s30Response200ShopDocuments), total_count: 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 }; /** * S30 - List shop's documents * * GET /api/shops/documents * * Also accepts auth: OAuth-2 */ export const getApiApiShopsDocuments = async (args: GetApiApiShopsDocumentsArgs, options?: GetApiApiShopsDocumentsOptions) => { const {baseUrl = "https://your-instance.mirakl.net", fetch: fetchFn = fetch, FrontBearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.shop_ids != null) query.append("shop_ids", String(args.shop_ids)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (FrontBearerToken !== undefined) headers.set('authorization', `Bearer ${FrontBearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/shops/documents${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(s30Response200, await res.json()) };