import {z} from 'zod' export type Page = {author?: ({displayName?: string | undefined, id?: string | undefined, image?: ({url?: string | undefined}) | undefined, url?: string | undefined}) | undefined, blog?: ({id?: string | undefined}) | undefined, content?: string | undefined, etag?: string | undefined, id?: string | undefined, kind?: string | undefined, published?: string | undefined, selfLink?: string | undefined, status?: ('LIVE' | 'DRAFT' | 'SOFT_TRASHED') | undefined, title?: string | undefined, trashed?: string | undefined, updated?: string | undefined, url?: string | undefined}; export type UpdateApiV3BlogsBlogIdPagesPageIdArgs = {blogId: string, pageId: string, publish?: boolean | undefined, revert?: boolean | undefined, body: Page}; export type UpdateApiV3BlogsBlogIdPagesPageIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({author: z.object({displayName: z.string().optional(), id: z.string().optional(), image: z.object({url: z.string().optional()}).optional(), url: z.string().optional()}).optional(), blog: z.object({id: z.string().optional()}).optional(), content: z.string().optional(), etag: z.string().optional(), id: z.string().optional(), kind: z.string().optional(), published: z.string().optional(), selfLink: z.string().optional(), status: z.enum(["LIVE", "DRAFT", "SOFT_TRASHED"]).optional(), title: z.string().optional(), trashed: z.string().optional(), updated: z.string().optional(), url: z.string().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 }; /** * Updates a page by blog id and page id. * * PUT /v3/blogs/{blogId}/pages/{pageId} */ export const updateApiV3BlogsBlogIdPagesPageId = async (args: UpdateApiV3BlogsBlogIdPagesPageIdArgs, options?: UpdateApiV3BlogsBlogIdPagesPageIdOptions) => { const {baseUrl = "https://blogger.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.publish != null) query.append("publish", String(args.publish)) if (args.revert != null) query.append("revert", String(args.revert)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/blogs/${encodeURIComponent(String(args.blogId))}/pages/${encodeURIComponent(String(args.pageId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(page, await res.json()) };