feat(web,mobile): add @bytelyst/billing-client and platform-client
Web: - New lib/billing-client.ts: factory wrapper using shared getAccessToken. - Add @bytelyst/billing-client to web deps. Mobile: - New lib/billing-client.ts: factory wrapper using MMKV token storage. - New lib/platform-api.ts: typed platform-client wrapper for settings, sessions, and profile management. - Add @bytelyst/billing-client and @bytelyst/platform-client to deps.
This commit is contained in:
parent
61de6ce94a
commit
4813c850a3
@ -17,6 +17,7 @@
|
||||
"dependencies": {
|
||||
"@bytelyst/api-client": "*",
|
||||
"@bytelyst/auth-client": "*",
|
||||
"@bytelyst/billing-client": "*",
|
||||
"@bytelyst/blob-client": "*",
|
||||
"@bytelyst/broadcast-client": "*",
|
||||
"@bytelyst/design-tokens": "*",
|
||||
@ -25,6 +26,7 @@
|
||||
"@bytelyst/feedback-client": "*",
|
||||
"@bytelyst/kill-switch-client": "*",
|
||||
"@bytelyst/offline-queue": "*",
|
||||
"@bytelyst/platform-client": "*",
|
||||
"@bytelyst/survey-client": "*",
|
||||
"@bytelyst/telemetry-client": "*",
|
||||
"expo": "~55.0.4",
|
||||
|
||||
20
mobile/src/lib/billing-client.ts
Normal file
20
mobile/src/lib/billing-client.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { createBillingClient, type BillingClient } from '@bytelyst/billing-client';
|
||||
import { API_CONFIG, PRODUCT_ID } from '../api/config';
|
||||
import { mmkvStorage } from '../store/mmkv-storage';
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
return mmkvStorage.getItem(`${PRODUCT_ID}_access_token`);
|
||||
}
|
||||
|
||||
let _client: BillingClient | null = null;
|
||||
|
||||
export function getBillingClient(): BillingClient {
|
||||
if (!_client) {
|
||||
_client = createBillingClient({
|
||||
baseUrl: API_CONFIG.platformBaseUrl,
|
||||
productId: PRODUCT_ID,
|
||||
getAccessToken,
|
||||
});
|
||||
}
|
||||
return _client;
|
||||
}
|
||||
54
mobile/src/lib/platform-api.ts
Normal file
54
mobile/src/lib/platform-api.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { createPlatformClient, type PlatformClient } from '@bytelyst/platform-client';
|
||||
import { API_CONFIG, PRODUCT_ID } from '../api/config';
|
||||
import { mmkvStorage } from '../store/mmkv-storage';
|
||||
|
||||
function getAccessToken(): string | null {
|
||||
return mmkvStorage.getItem(`${PRODUCT_ID}_access_token`);
|
||||
}
|
||||
|
||||
let _client: PlatformClient | null = null;
|
||||
|
||||
function getClient(): PlatformClient {
|
||||
if (!_client) {
|
||||
_client = createPlatformClient({
|
||||
baseUrl: API_CONFIG.platformBaseUrl,
|
||||
productId: PRODUCT_ID,
|
||||
getAccessToken,
|
||||
});
|
||||
}
|
||||
return _client;
|
||||
}
|
||||
|
||||
export interface UserSettings {
|
||||
theme?: 'dark' | 'light' | 'system';
|
||||
language?: string;
|
||||
notificationsEnabled?: boolean;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface ActiveSession {
|
||||
id: string;
|
||||
deviceName: string;
|
||||
lastActiveAt: string;
|
||||
isCurrent: boolean;
|
||||
}
|
||||
|
||||
export async function getUserSettings(): Promise<UserSettings> {
|
||||
return getClient().get<UserSettings>('/settings');
|
||||
}
|
||||
|
||||
export async function updateUserSettings(settings: Partial<UserSettings>): Promise<UserSettings> {
|
||||
return getClient().put<UserSettings>('/settings', settings);
|
||||
}
|
||||
|
||||
export async function listSessions(): Promise<ActiveSession[]> {
|
||||
return getClient().get<ActiveSession[]>('/sessions');
|
||||
}
|
||||
|
||||
export async function revokeSession(sessionId: string): Promise<void> {
|
||||
await getClient().del(`/sessions/${sessionId}`);
|
||||
}
|
||||
|
||||
export async function updateProfile(updates: { displayName?: string }): Promise<void> {
|
||||
await getClient().put('/auth/profile', updates);
|
||||
}
|
||||
@ -15,6 +15,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@bytelyst/api-client": "*",
|
||||
"@bytelyst/billing-client": "*",
|
||||
"@bytelyst/design-tokens": "*",
|
||||
"@bytelyst/blob-client": "*",
|
||||
"@bytelyst/diagnostics-client": "*",
|
||||
|
||||
18
web/src/lib/billing-client.ts
Normal file
18
web/src/lib/billing-client.ts
Normal file
@ -0,0 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { createBillingClient, type BillingClient } from "@bytelyst/billing-client";
|
||||
import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config";
|
||||
import { getAccessToken } from "@/lib/api-helpers";
|
||||
|
||||
let _client: BillingClient | null = null;
|
||||
|
||||
export function getBillingClient(): BillingClient {
|
||||
if (!_client) {
|
||||
_client = createBillingClient({
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
productId: PRODUCT_ID,
|
||||
getAccessToken,
|
||||
});
|
||||
}
|
||||
return _client;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user