Files
makelore/src/lib/works-billing.ts
T

20 lines
1.5 KiB
TypeScript

import type { WorksBillingSummary, WorksPointHistory, WorksRechargeOrder, WorksTokenPointBalance } from '../../shared/works-billing';
import { hostApiFetch } from './host-api';
import { invokeIpc } from './api-client';
export type { WorksBillingSummary, WorksPointHistory, WorksRechargeOrder, WorksRechargeProduct, WorksTokenPointBalance } from '../../shared/works-billing';
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const result = await hostApiFetch<{ success: boolean; data: T }>(`/api/works/billing${path}`, init);
if (!result.success) throw new Error('词元点数服务暂时不可用');
return result.data;
}
export const fetchWorksBillingSummary = () => request<WorksBillingSummary>('/me');
export const openWorksBillingAccount = () => invokeIpc('shell:openExternal', 'https://square.nianxx.cn/#profile');
export const fetchWorksTokenPointBalance = () => request<WorksTokenPointBalance>('/points');
export const fetchWorksPointHistory = (offset = 0) => request<WorksPointHistory>(`/points/transactions?offset=${offset}`);
export const fetchWorksRechargeOrders = (offset = 0) => request<{ items: WorksRechargeOrder[] }>(`/recharge/orders?offset=${offset}`);
export const fetchWorksRechargeOrder = (id: string) => request<WorksRechargeOrder>(`/recharge/orders/${encodeURIComponent(id)}`);
export const createWorksRechargeOrder = (productId: string, requestId: string) => request<WorksRechargeOrder>('/recharge/orders', {
method: 'POST', body: JSON.stringify({ productId, requestId }),
});