import {z} from 'zod' export type GetApiCabinetAdminUsersUserIdSyncStatusArgs = {user_id: number}; export type GetApiCabinetAdminUsersUserIdSyncStatusOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const panelSyncStatusResponse = z.object({user_id: z.number().int(), telegram_id: z.number().int().nullable().optional(), remnawave_uuid: z.string().nullable().optional(), last_sync: z.string().nullable().optional(), bot_subscription_status: z.string().nullable().optional(), bot_subscription_end_date: z.string().nullable().optional(), bot_traffic_limit_gb: z.number().int().optional(), bot_traffic_used_gb: z.number().optional(), bot_device_limit: z.number().int().optional(), bot_squads: z.array(z.string()).optional(), panel_found: z.boolean().optional(), panel_status: z.string().nullable().optional(), panel_expire_at: z.string().nullable().optional(), panel_traffic_limit_gb: z.number().optional(), panel_traffic_used_gb: z.number().optional(), panel_device_limit: z.number().int().optional(), panel_squads: z.array(z.string()).optional(), has_differences: z.boolean().optional(), differences: z.array(z.string()).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 }; /** * Get User Sync Status * * GET /cabinet/admin/users/{user_id}/sync/status */ export const getApiCabinetAdminUsersUserIdSyncStatus = async (args: GetApiCabinetAdminUsersUserIdSyncStatusArgs, options: GetApiCabinetAdminUsersUserIdSyncStatusOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/users/${encodeURIComponent(String(args.user_id))}/sync/status${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(panelSyncStatusResponse, await res.json()) };