import {z} from 'zod' export type CreateApiV1EventGatewaysGatewayIdDataPlaneCertificatesArgs = {body: {certificate: string, name?: (string | null) | undefined, description?: string | undefined}}; export type CreateApiV1EventGatewaysGatewayIdDataPlaneCertificatesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createdAt = z.string(); export const updatedAt = z.string(); export const certificateMetadata = z.object({issuer: z.string().nullable().optional(), subject: z.string().nullable().optional(), key_usages: z.array(z.string()).nullable().optional(), expiry: z.number().int().nullable().optional(), san_names: z.array(z.string()).nullable().optional(), dns_names: z.array(z.string()).nullable().optional(), email_addresses: z.array(z.string()).nullable().optional(), ip_addresses: z.array(z.string()).nullable().optional(), uris: z.array(z.string()).nullable().optional(), sha256_fingerprint: z.string().nullable().optional()}); export const eventGatewayDataPlaneCertificate = z.object({id: z.string(), certificate: z.string(), name: z.string().min(1).max(255).nullable().optional(), description: z.string().nullable().optional(), created_at: createdAt, updated_at: updatedAt, metadata: certificateMetadata.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 }; /** * Create a New DataPlane Certificate * * POST /v1/event-gateways/{gatewayId}/data-plane-certificates * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const createApiV1EventGatewaysGatewayIdDataPlaneCertificates = async (args: CreateApiV1EventGatewaysGatewayIdDataPlaneCertificatesArgs, options?: CreateApiV1EventGatewaysGatewayIdDataPlaneCertificatesOptions) => { 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(/\/+$/, '')}/v1/event-gateways/${encodeURIComponent(String(args.gatewayId))}/data-plane-certificates${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(eventGatewayDataPlaneCertificate, await res.json()) };