import {z} from 'zod' export type GetApiAppAppIdEnterprisePortalFailedLoginAttemptsArgs = {app_id: string, limit?: number | undefined, offset?: number | undefined, filterEmail?: string | undefined, sort?: string | undefined, order?: string | undefined}; export type GetApiAppAppIdEnterprisePortalFailedLoginAttemptsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const failedLoginAttempt = z.object({app_id: z.string().optional(), created_at: z.string().optional(), email_address: z.string().optional(), id: z.string().optional(), ip_address: z.string().optional(), login_url: z.string().optional(), team_id: z.string().optional()}); export const getApiAppAppIdEnterprisePortalFailedLoginAttemptsResponse = z.object({attempts: z.array(failedLoginAttempt).optional(), total: z.number().int().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 failed login attempts * * GET /app/{app_id}/enterprise-portal/failed-login-attempts */ export const getApiAppAppIdEnterprisePortalFailedLoginAttempts = async (args: GetApiAppAppIdEnterprisePortalFailedLoginAttemptsArgs, options?: GetApiAppAppIdEnterprisePortalFailedLoginAttemptsOptions) => { const {baseUrl = "https://api.replicated.com/vendor/v3", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.filterEmail != null) query.append("filterEmail", String(args.filterEmail)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/app/${encodeURIComponent(String(args.app_id))}/enterprise-portal/failed-login-attempts${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(getApiAppAppIdEnterprisePortalFailedLoginAttemptsResponse, await res.json()) };