File size: 2,807 Bytes
6aa6081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47a0040
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import api from './api';

export interface DeveloperDashboard {
  total_accounts: number;
  active_accounts: number;
  trial_accounts: number;
  total_users: number;
  accounts_by_date: { date: string; count: number }[];
  errors_trend: { date: string; count: number }[];
  accounts: DeveloperAccount[];
}

export interface DeveloperAccount {
  id: number;
  name: string;
  is_active: boolean;
  trial_end_date: string | null;
  plan: string;
  user_count: number;
}

export interface SystemLogEntry {
  id: number;
  level: string;
  message: string;
  traceback: string | null;
  endpoint: string | null;
  method: string | null;
  account_id: number | null;
  user_id: number | null;
  ip_address: string | null;
  created_at: string;
}

export interface PaginatedLogs {
  items: SystemLogEntry[];
  total: number;
  page: number;
  per_page: number;
  total_pages: number;
}

export async function getDeveloperDashboard(): Promise<DeveloperDashboard> {
  const { data } = await api.get('/developer/dashboard');
  return data;
}

export async function listDeveloperAccounts(search?: string): Promise<DeveloperAccount[]> {
  const params = search ? { search } : {};
  const { data } = await api.get('/developer/accounts', { params });
  return data;
}

export async function toggleAccountActive(accountId: number): Promise<{ id: number; is_active: boolean }> {
  const { data } = await api.put(`/developer/accounts/${accountId}/toggle-active`);
  return data;
}

export async function setAccountTrial(accountId: number, days: number): Promise<{ id: number; trial_end_date: string }> {
  const { data } = await api.put(`/developer/accounts/${accountId}/trial`, null, { params: { days } });
  return data;
}

export async function getSystemLogs(page = 1, perPage = 20, level?: string): Promise<PaginatedLogs> {
  const params: Record<string, any> = { page, per_page: perPage };
  if (level) params.level = level;
  const { data } = await api.get('/developer/logs', { params });
  return data;
}

export async function getLogsTrend(days = 30): Promise<{ date: string; count: number }[]> {
  const { data } = await api.get('/developer/logs/trend', { params: { days } });
  return data;
}

export async function getUsersByAccount(): Promise<{ account_name: string; account_id: number; user_count: number }[]> {
  const { data } = await api.get('/developer/users-by-account');
  return data;
}

export function getExportUrl(): string {
  return `${api.defaults.baseURL}/developer/export`;
}

export interface PurgeDemoResponse {
  success: boolean;
  demo_account_id: number;
  deleted: Record<string, number>;
  reseeded: boolean;
}

export async function purgeDemoData(password: string): Promise<PurgeDemoResponse> {
  const { data } = await api.post('/developer/purge-demo', { password });
  return data;
}