import {z} from 'zod' export type V2PortalName = string; export type V2PortalDisplayName = string; export type V2PortalDescription = string | null; export type V2DefaultApplicationAuthStratID = string | null; export type LabelsUpdate = {[key: string]: string | null} | null; export type V2UpdatePortalRequest = {name?: V2PortalName | undefined, display_name?: V2PortalDisplayName | undefined, description?: V2PortalDescription | undefined, is_public?: (boolean | null) | undefined, rbac_enabled?: (boolean | null) | undefined, auto_approve_applications?: (boolean | null) | undefined, auto_approve_developers?: (boolean | null) | undefined, custom_domain?: (string | null) | undefined, custom_client_domain?: (string | null) | undefined, default_application_auth_strategy_id?: V2DefaultApplicationAuthStratID | undefined, labels?: LabelsUpdate | undefined}; export type PatchApiV2PortalsPortalIdClassicArgs = {body: V2UpdatePortalRequest}; export type PatchApiV2PortalsPortalIdClassicOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const createdAt = z.string(); export const updatedAt = z.string(); export const v2PortalName = z.string().min(1).max(255); export const v2PortalDisplayName = z.string().min(1).max(255); export const v2PortalDescription = z.string().max(512).nullable(); export const v2DefaultApplicationAuthStratID = z.string().nullable(); export const labels = z.record(z.string(), z.string().min(1).max(63).nullable()); export const v2UpdatePortalResponse = z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, name: v2PortalName, display_name: v2PortalDisplayName, description: v2PortalDescription, default_domain: z.string(), is_public: z.boolean(), rbac_enabled: z.boolean(), auto_approve_applications: z.boolean(), auto_approve_developers: z.boolean(), custom_domain: z.string().nullable(), custom_client_domain: z.string().nullable(), default_application_auth_strategy_id: v2DefaultApplicationAuthStratID.optional(), labels: labels.optional(), application_count: z.number(), developer_count: z.number(), published_product_count: z.number()}); 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 Portal * * PATCH /v2/portals/{portalId}#classic * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const patchApiV2PortalsPortalIdClassic = async (args: PatchApiV2PortalsPortalIdClassicArgs, options?: PatchApiV2PortalsPortalIdClassicOptions) => { 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(/\/+$/, '')}/v2/portals/${encodeURIComponent(String(args.portalId))}#classic${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(v2UpdatePortalResponse, await res.json()) };