54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { apiClient, getDataOrDefault } from "@/lib/api";
|
|
|
|
export interface TopUpRequest {
|
|
quotaMb: number;
|
|
}
|
|
|
|
export interface ChangePlanRequest {
|
|
newPlanCode: string;
|
|
assignGlobalIp: boolean;
|
|
scheduledAt?: string;
|
|
}
|
|
|
|
export interface CancelRequest {
|
|
scheduledAt: string;
|
|
}
|
|
|
|
export interface SimInfo<T, E = unknown> {
|
|
details: T;
|
|
error?: E;
|
|
}
|
|
|
|
export const simActionsService = {
|
|
async topUp(subscriptionId: string, request: TopUpRequest): Promise<void> {
|
|
await apiClient.POST("/api/subscriptions/{subscriptionId}/sim/top-up", {
|
|
params: { path: { subscriptionId } },
|
|
body: request,
|
|
});
|
|
},
|
|
|
|
async changePlan(subscriptionId: string, request: ChangePlanRequest): Promise<void> {
|
|
await apiClient.POST("/api/subscriptions/{subscriptionId}/sim/change-plan", {
|
|
params: { path: { subscriptionId } },
|
|
body: request,
|
|
});
|
|
},
|
|
|
|
async cancel(subscriptionId: string, request: CancelRequest): Promise<void> {
|
|
await apiClient.POST("/api/subscriptions/{subscriptionId}/sim/cancel", {
|
|
params: { path: { subscriptionId } },
|
|
body: request,
|
|
});
|
|
},
|
|
|
|
async getSimInfo<T, E = unknown>(subscriptionId: string): Promise<SimInfo<T, E> | null> {
|
|
const response = await apiClient.GET<SimInfo<T, E> | null>(
|
|
"/api/subscriptions/{subscriptionId}/sim/info",
|
|
{
|
|
params: { path: { subscriptionId } },
|
|
}
|
|
);
|
|
return getDataOrDefault<SimInfo<T, E> | null>(response, null);
|
|
},
|
|
};
|