import {z} from 'zod' export type LegacyStringFieldFilter = {eq?: string | undefined, contains?: string | undefined}; export type GetApiV3TeamsTeamIdSystemAccountsArgs = {'page[size]'?: number | undefined, 'page[number]'?: number | undefined, filter?: ({name?: LegacyStringFieldFilter | undefined}) | undefined}; export type GetApiV3TeamsTeamIdSystemAccountsOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const pageMeta = z.object({number: z.number(), size: z.number(), total: z.number()}); export const paginatedMeta = z.object({page: pageMeta}); export const systemAccount = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), konnect_managed: z.boolean().optional()}); export const getApiV3TeamsTeamIdSystemAccountsResponse = z.object({meta: paginatedMeta.optional(), data: z.array(systemAccount).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 }; /** * List System Accounts on a Team * * GET /v3/teams/{teamId}/system-accounts * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV3TeamsTeamIdSystemAccounts = async (args: GetApiV3TeamsTeamIdSystemAccountsArgs, options?: GetApiV3TeamsTeamIdSystemAccountsOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[number]'] != null) query.append("page[number]", String(args['page[number]'])) if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/teams/${encodeURIComponent(String(args.teamId))}/system-accounts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV3TeamsTeamIdSystemAccountsResponse, await res.json()) };