import {z} from 'zod' export type UpdatePortalCustomDomainSSL = {custom_certificate?: string | undefined, custom_private_key?: string | undefined, skip_ca_check?: boolean | undefined}; export type UpdatePortalCustomDomainRequest = {enabled?: boolean | undefined, ssl?: UpdatePortalCustomDomainSSL | undefined}; export type PatchApiV3PortalsPortalIdCustomDomainArgs = {body: UpdatePortalCustomDomainRequest}; export type PatchApiV3PortalsPortalIdCustomDomainOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const portalCustomDomainVerificationMethod = z.enum(["http", "custom_certificate"]); export const portalCustomDomainVerificationStatus = z.enum(["verified", "pending", "error"]); export const portalCustomDomainValidationErrors = z.array(z.string()); export const portalCustomDomainSSL = z.object({domain_verification_method: portalCustomDomainVerificationMethod, verification_status: portalCustomDomainVerificationStatus, validation_errors: portalCustomDomainValidationErrors.optional(), uploaded_at: z.string().optional(), expires_at: z.string().optional(), skip_ca_check: z.boolean().optional()}); export const portalCustomDomainCnameStatus = z.enum(["verified", "pending"]); export const createdAt = z.string(); export const updatedAt = z.string(); export const portalCustomDomain = z.object({hostname: z.string(), enabled: z.boolean(), ssl: portalCustomDomainSSL, cname_status: portalCustomDomainCnameStatus, created_at: createdAt, updated_at: updatedAt}); 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 }; /** * Enable or Disable Domain * * PATCH /v3/portals/{portalId}/custom-domain * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const patchApiV3PortalsPortalIdCustomDomain = async (args: PatchApiV3PortalsPortalIdCustomDomainArgs, options?: PatchApiV3PortalsPortalIdCustomDomainOptions) => { 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))}/custom-domain${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(portalCustomDomain, await res.json()) };