import {z} from 'zod' export type PageSlug = string; export type PageTitle = string; export type PageContent = string; export type VisibilityStatus = 'public' | 'private'; export type PublishedStatus = 'published' | 'unpublished'; export type Description = string; export type ParentPageId = string | null; export type UpdatePortalPageRequest = {slug?: PageSlug | undefined, title?: PageTitle | undefined, content?: PageContent | undefined, visibility?: VisibilityStatus | undefined, status?: PublishedStatus | undefined, description?: Description | undefined, parent_page_id?: ParentPageId | undefined}; export type PatchApiV3PortalsPortalIdPagesPageIdArgs = {portalId: string, pageId: string, body: UpdatePortalPageRequest}; export type PatchApiV3PortalsPortalIdPagesPageIdOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const pageSlug = z.string().max(512); export const pageTitle = z.string().max(512); export const pageContent = z.string().max(1000000); export const visibilityStatus = z.enum(["public", "private"]); export const publishedStatus = z.enum(["published", "unpublished"]); export const description = z.string().max(160); export const createdAt = z.string(); export const updatedAt = z.string(); export const parentPageId = z.string().nullable(); export const portalPageResponse = z.object({id: uUID, slug: pageSlug, title: pageTitle, content: pageContent, visibility: visibilityStatus, status: publishedStatus, description: description.optional(), created_at: createdAt, updated_at: updatedAt, parent_page_id: parentPageId}); 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 Page * * PATCH /v3/portals/{portalId}/pages/{pageId} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const patchApiV3PortalsPortalIdPagesPageId = async (args: PatchApiV3PortalsPortalIdPagesPageIdArgs, options?: PatchApiV3PortalsPortalIdPagesPageIdOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/portals/${encodeURIComponent(String(args.portalId))}/pages/${encodeURIComponent(String(args.pageId))}${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(portalPageResponse, await res.json()) };