import {z} from 'zod' export type ApplicationOwnerType = 'developer' | 'team'; export type ApplicationOwnerId = string; export type ApplicationOwner = {type: ApplicationOwnerType, id: ApplicationOwnerId}; export type UpdateApplicationRequest = {owner?: ApplicationOwner | undefined}; export type PatchApiV3PortalsPortalIdApplicationsApplicationIdArgs = {body: UpdateApplicationRequest}; export type PatchApiV3PortalsPortalIdApplicationsApplicationIdOptions = {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 labelsUpdate = z.record(z.string(), z.string().min(1).max(63).nullable()).nullable(); export const applicationOwnerType = z.enum(["developer", "team"]); export const applicationOwnerId = z.string(); export const applicationOwner = z.object({type: applicationOwnerType, id: applicationOwnerId}); export const getApplicationResponse = z.object({id: uUID, created_at: createdAt, updated_at: updatedAt, name: z.string(), description: z.string().nullable(), labels: labelsUpdate, client_id: z.string().optional(), registration_count: z.number(), dcr_provider: z.object({id: uUID}).optional(), portal: z.object({id: uUID}), auth_strategy: z.object({id: z.string(), name: z.string(), credential_type: z.enum(["key_auth", "client_credentials", "self_managed_client_credentials"]), key_names: z.array(z.string()).optional(), ttl: z.object({value: z.number().int().gte(1).optional(), unit: z.enum(["days", "weeks", "years"]).optional()}).optional(), auth_methods: z.array(z.string()).optional(), available_scopes: z.array(z.string()).optional()}), granted_scopes: z.array(z.string()).nullable().optional(), owner: applicationOwner.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 }; /** * Update Application * * PATCH /v3/portals/{portalId}/applications/{applicationId} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const patchApiV3PortalsPortalIdApplicationsApplicationId = async (args: PatchApiV3PortalsPortalIdApplicationsApplicationIdArgs, options?: PatchApiV3PortalsPortalIdApplicationsApplicationIdOptions) => { 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))}/applications/${encodeURIComponent(String(args.applicationId))}${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(getApplicationResponse, await res.json()) };