import {z} from 'zod' export type AdminV1AuthSessionSettings = {defaultTtlHours?: number | undefined, loginFailureWindowMinutes?: number | undefined, loginLockMinutes?: number | undefined, loginMaxFailures?: number | undefined, maxAbsoluteTtlHours?: number | undefined, rememberMeTtlHours?: number | undefined}; export type AdminV1UpdateAuthSessionSettingsRequest = {settings?: AdminV1AuthSessionSettings | undefined}; export type UpdateApiV1AdminSettingsAuthSessionArgs = {body: AdminV1UpdateAuthSessionSettingsRequest}; export type UpdateApiV1AdminSettingsAuthSessionOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const adminV1UpdateAuthSessionSettingsReply = z.object({ok: z.boolean().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 }; /** * UpdateAuthSessionSettings 更新会话 TTL 策略;TTL 数值越界返回 400。 * * PUT /v1/admin/settings/auth-session */ export const updateApiV1AdminSettingsAuthSession = async (args: UpdateApiV1AdminSettingsAuthSessionArgs, options: UpdateApiV1AdminSettingsAuthSessionOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/settings/auth-session${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(adminV1UpdateAuthSessionSettingsReply, await res.json()) };