-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathclient-api.ts
More file actions
121 lines (111 loc) · 3.39 KB
/
Copy pathclient-api.ts
File metadata and controls
121 lines (111 loc) · 3.39 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use client';
import { browserApiClient } from '@/lib/api/typed/browser';
import type {
MineruTokenTestResponse,
QuotaUpdateRequest,
QuotaUpdateResponse,
Settings,
SystemDefaultQuotasResponse,
SystemDefaultQuotasUpdateRequest,
SystemDefaultQuotasUpdateResponse,
UserQuotaInfo,
} from './types';
// Single canonical surface for admin control-plane client calls: settings,
// parser/MinerU token test, admin-side system default quotas, per-user
// quota CRUD + recalculate. Workspace-side quota (`features/quota/*`) is
// kept separate per design-lock msg=5f0a370b decision 2e.
export async function updateSettings(input: Settings): Promise<Settings> {
const { data } = await browserApiClient.PUT('/api/v2/settings', {
body: input,
});
if (!data) {
throw new Error('updateSettings: empty response body');
}
return data;
}
// Note: `Settings_test_mineru_token` response body is typed as `unknown`
// in the public OpenAPI spec, but the backend returns the
// `MineruTokenTestResponse` shape at runtime. Cast at the adapter
// boundary so callers get the concrete type. Phase 4 governance may
// tighten the schema to remove this cast.
export async function testMineruToken(
token: string,
): Promise<MineruTokenTestResponse> {
const { data } = await browserApiClient.POST(
'/api/v2/settings/test_mineru_token',
{
body: { token },
},
);
if (!data) {
throw new Error('testMineruToken: empty response body');
}
return data as MineruTokenTestResponse;
}
export async function updateSystemDefaultQuotas(
input: SystemDefaultQuotasUpdateRequest,
): Promise<SystemDefaultQuotasUpdateResponse> {
const { data } = await browserApiClient.PUT(
'/api/v1/system/default-quotas',
{
body: input,
},
);
if (!data) {
throw new Error('updateSystemDefaultQuotas: empty response body');
}
return data;
}
export async function getSystemDefaultQuotas(): Promise<SystemDefaultQuotasResponse> {
const { data } = await browserApiClient.GET(
'/api/v1/system/default-quotas',
{},
);
if (!data) {
throw new Error('getSystemDefaultQuotas: empty response body');
}
return data;
}
export async function getUserQuota(userId: string): Promise<UserQuotaInfo> {
const { data } = await browserApiClient.GET('/api/v1/quotas', {
params: { query: { user_id: userId } },
});
if (!data) {
throw new Error('getUserQuota: empty response body');
}
if ('items' in data) {
throw new Error(
'getUserQuota: expected UserQuotaInfo shape, got UserQuotaList',
);
}
return data;
}
export async function updateUserQuota(
userId: string,
input: QuotaUpdateRequest,
): Promise<QuotaUpdateResponse> {
const { data } = await browserApiClient.PUT(
'/api/v1/quotas/{user_id}',
{
params: { path: { user_id: userId } },
body: input,
},
);
if (!data) {
throw new Error('updateUserQuota: empty response body');
}
return data;
}
// Backend currently returns `unknown` (no typed schema for recalculate
// response); adapter exposes the raw JSON and lets callers decide how to
// interpret it. If Phase 4 governance formalizes the response shape, tighten
// the return type.
export async function recalculateUserQuota(userId: string): Promise<unknown> {
const { data } = await browserApiClient.POST(
'/api/v1/quotas/{user_id}/recalculate',
{
params: { path: { user_id: userId } },
},
);
return data;
}