import {z} from 'zod' export type GetApiCompatV2JobsGetJobsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCompatV2JobsGetJobsResponse = z.array(z.union([z.object({id: z.string(), status: z.enum(["CREATE", "RUN", "FAIL", "SUCCESS"]), type: z.literal("IMPORT"), userId: z.string(), resultCode: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable(), progress: z.number().int().gte(-9007199254740991).lte(9007199254740991), meta: z.object({importType: z.enum(["lcb", "fdxz", "textFiles", "pepperplate", "recipekeeper", "paprika", "cookmate", "jsonld", "csv", "urls", "pdfs", "images", "enex", "copymethat", "mela", "crouton", "cookbookmanagercom", "flavorish"]).optional(), importLabels: z.array(z.string()).optional(), importStorageKey: z.string().optional(), importStorageBucket: z.string().optional(), partialCount: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), failedCount: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), failedUrls: z.array(z.string()).optional(), options: z.object({excludeImages: z.boolean().optional(), includeStockRecipes: z.boolean().optional(), includeTechniques: z.boolean().optional()}).optional(), language: z.string().max(254).optional()}), createdAt: z.string(), updatedAt: z.string()}), z.object({id: z.string(), status: z.enum(["CREATE", "RUN", "FAIL", "SUCCESS"]), type: z.literal("EXPORT"), userId: z.string(), resultCode: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable(), progress: z.number().int().gte(-9007199254740991).lte(9007199254740991), meta: z.object({exportType: z.enum(["txt", "jsonld", "pdf"]).optional(), exportScope: z.enum(["all", "recipeids"]).optional(), exportStorageBucket: z.string().optional(), exportStorageKey: z.string().optional(), exportDownloadUrl: z.string().optional(), recipeIds: z.array(z.string()).optional(), language: z.string().max(254).optional()}), createdAt: z.string(), updatedAt: z.string()}), z.object({id: z.string(), status: z.enum(["CREATE", "RUN", "FAIL", "SUCCESS"]), type: z.literal("COOKBOOK"), userId: z.string(), resultCode: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable(), progress: z.number().int().gte(-9007199254740991).lte(9007199254740991), meta: z.object({cookbookTitle: z.string().optional(), cookbookSubtitle: z.string().optional(), cookbookIntroduction: z.string().optional(), cookbookAuthor: z.string().optional(), cookbookIncludeToc: z.boolean().optional(), cookbookIncludeImages: z.boolean().optional(), cookbookIncludeLabels: z.boolean().optional(), cookbookIncludeLastMade: z.boolean().optional(), cookbookIncludeLinkedRecipes: z.boolean().optional(), cookbookIncludeRecipeSageUrl: z.boolean().optional(), cookbookStorageBucket: z.string().optional(), cookbookStorageKey: z.string().optional(), cookbookDownloadUrl: z.string().optional(), recipeIds: z.array(z.string()).optional(), language: z.string().max(254).optional()}), createdAt: z.string(), updatedAt: z.string()})])); 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 of the caller's jobs * * GET /compat/v2/jobs/getJobs */ export const getApiCompatV2JobsGetJobs = async (options?: GetApiCompatV2JobsGetJobsOptions) => { const {baseUrl = "https://api.recipesage.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/compat/v2/jobs/getJobs${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(getApiCompatV2JobsGetJobsResponse, await res.json()) };