import {z} from 'zod' export type PatchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleIdArgs = {accountId: string, blogId: string, articleId: string, body: {title?: string | undefined, bodyHtml?: string | undefined, handle?: string | undefined, tags?: Array | undefined, author?: string | undefined, excerpt?: string | undefined, image?: ({url: string, altText?: string | undefined}) | undefined, seo?: ({title?: string | undefined, description?: string | undefined}) | undefined, isPublished?: boolean | undefined, publishDate?: string | undefined, fieldData?: {[key: string]: unknown} | undefined}}; export type PatchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const blogArticle = z.object({id: z.string().optional(), blogId: z.string().optional(), platform: z.enum(["shopify", "wordpress", "wix", "webflow"]).optional(), title: z.string().optional(), bodyHtml: z.string().nullable().optional(), handle: z.string().optional(), url: z.string().nullable().optional(), tags: z.array(z.string()).optional(), author: z.string().nullable().optional(), excerpt: z.string().nullable().optional(), image: z.object({url: z.string().optional(), altText: z.string().nullable().optional()}).nullable().optional(), isPublished: z.boolean().optional(), publishedAt: z.string().nullable().optional(), status: z.enum(["publish", "future", "draft", "pending", "private"]).optional(), publishDate: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional()}); export const patchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleIdResponse = z.object({platform: z.enum(["shopify", "wordpress", "wix", "webflow"]).optional(), article: blogArticle.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 }; /** * Update a blog article * * PATCH /v1/accounts/{accountId}/blogs/{blogId}/articles/{articleId} */ export const patchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleId = async (args: PatchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleIdArgs, options?: PatchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleIdOptions) => { const {baseUrl = "https://zernio.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.accountId))}/blogs/${encodeURIComponent(String(args.blogId))}/articles/${encodeURIComponent(String(args.articleId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV1AccountsAccountIdBlogsBlogIdArticlesArticleIdResponse, await res.json()) };