- Fix 98 TypeScript errors across 37 files: - Service layer double-unwrapping (subscriptionService, distributionService, gearService) - Self-referencing variables in SearchPageResults - FeedView/ExploreView .posts→.items alignment - useQueueSync Zustand subscribe API - AdminAuditLogsView missing interface fields - Toast proxy type, interceptor type narrowing - 22 unused imports/variables removed - 5 storybook mock data fixes - Align frontend API calls with backend endpoints: - Analytics: useAnalyticsView now calls /creator/analytics/dashboard (was /analytics) - Chat: chatService uses /conversations (was mock data), WS URL from backend token - Dashboard StatsSection: uses real /dashboard API data (was hardcoded zeros) - Settings: suppress 2FA toast error when endpoint unavailable - Fix marketplace products: seed uses 'active' status (was 'published') - Enrich seed: admin follows all creators (feed has content) - Optimize bundle: vendor catch-all 793KB→318KB gzip (-60%) Split into vendor-charts, vendor-emoji, vendor-swagger, vendor-media, etc. - Clean repo: remove ~100 orphaned screenshots, audit reports, logs from root Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
96 lines
3.2 KiB
TypeScript
96 lines
3.2 KiB
TypeScript
import { apiClient } from './api/client';
|
|
import type {
|
|
SubscriptionPlan,
|
|
UserSubscription,
|
|
SubscriptionInvoice,
|
|
SubscribeRequest,
|
|
SubscribeResponse,
|
|
BillingCycle,
|
|
} from '../types/subscription';
|
|
|
|
export const subscriptionService = {
|
|
/** List all available subscription plans */
|
|
listPlans: async (): Promise<SubscriptionPlan[]> => {
|
|
const response = await apiClient.get<{ plans: SubscriptionPlan[] }>(
|
|
'/subscriptions/plans',
|
|
);
|
|
return (response.data as { plans: SubscriptionPlan[] }).plans;
|
|
},
|
|
|
|
/** Get a specific plan by ID */
|
|
getPlan: async (planId: string): Promise<SubscriptionPlan> => {
|
|
const response = await apiClient.get<SubscriptionPlan>(
|
|
`/subscriptions/plans/${planId}`,
|
|
);
|
|
return response.data as SubscriptionPlan;
|
|
},
|
|
|
|
/** Get the current user's active subscription */
|
|
getMySubscription: async (): Promise<UserSubscription | null> => {
|
|
const response = await apiClient.get<{
|
|
subscription: UserSubscription | null;
|
|
}>('/subscriptions/me');
|
|
return (response.data as { subscription: UserSubscription | null }).subscription;
|
|
},
|
|
|
|
/** Subscribe to a plan */
|
|
subscribe: async (req: SubscribeRequest): Promise<SubscribeResponse> => {
|
|
const response = await apiClient.post<SubscribeResponse>(
|
|
'/subscriptions/subscribe',
|
|
req,
|
|
);
|
|
return response.data as SubscribeResponse;
|
|
},
|
|
|
|
/** Cancel the current subscription (access continues until end of period) */
|
|
cancelSubscription: async (): Promise<{
|
|
subscription: UserSubscription;
|
|
message: string;
|
|
}> => {
|
|
const response = await apiClient.post<{
|
|
subscription: UserSubscription;
|
|
message: string;
|
|
}>('/subscriptions/cancel');
|
|
return response.data as { subscription: UserSubscription; message: string };
|
|
},
|
|
|
|
/** Reactivate a canceled subscription */
|
|
reactivateSubscription: async (): Promise<UserSubscription> => {
|
|
const response = await apiClient.post<{
|
|
subscription: UserSubscription;
|
|
}>('/subscriptions/reactivate');
|
|
return (response.data as { subscription: UserSubscription }).subscription;
|
|
},
|
|
|
|
/** Change billing cycle (monthly/yearly) */
|
|
changeBillingCycle: async (
|
|
billingCycle: BillingCycle,
|
|
): Promise<UserSubscription> => {
|
|
const response = await apiClient.put<{
|
|
subscription: UserSubscription;
|
|
}>('/subscriptions/billing-cycle', { billing_cycle: billingCycle });
|
|
return (response.data as { subscription: UserSubscription }).subscription;
|
|
},
|
|
|
|
/** Get subscription invoices */
|
|
getInvoices: async (
|
|
limit = 20,
|
|
offset = 0,
|
|
): Promise<SubscriptionInvoice[]> => {
|
|
const response = await apiClient.get<{
|
|
invoices: SubscriptionInvoice[];
|
|
}>('/subscriptions/invoices', { params: { limit, offset } });
|
|
return (response.data as { invoices: SubscriptionInvoice[] }).invoices;
|
|
},
|
|
|
|
/** Get subscription history */
|
|
getHistory: async (
|
|
limit = 20,
|
|
offset = 0,
|
|
): Promise<UserSubscription[]> => {
|
|
const response = await apiClient.get<{
|
|
subscriptions: UserSubscription[];
|
|
}>('/subscriptions/history', { params: { limit, offset } });
|
|
return (response.data as { subscriptions: UserSubscription[] }).subscriptions;
|
|
},
|
|
};
|