2026-06-30 16:27:17 +08:00
|
|
|
import { http, getAccessToken } from './client';
|
refactor: replace Supabase SDK with self-hosted REST API client layer
WHY: migrating from Supabase BaaS to self-hosted iloom backend
(Go microservices) deployed on K3s. Supabase client and realtime
subscriptions no longer applicable.
HOW:
- add src/api/ layer (client.ts, auth.ts, purchaser.ts, textile.ts,
washing.ts, websocket.ts) targeting iloom-gateway REST endpoints
- rewrite all hooks (usePlanData, useInventoryData, useDashboardData,
useRealtime, etc.) to use new API client instead of Supabase queries
- rewrite all page/component data fetching and mutations accordingly
- delete src/supabase/client.ts, remove @supabase/supabase-js dep
- add Dockerfile (multi-stage node build + nginx) and nginx.conf
with reverse proxy to iloom-gateway for /api/ and /ws/ routes
- adjust webpack.config.js for API_URL environment variable injection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-14 12:38:47 +08:00
|
|
|
import type { Company, CompanyMember, Profile } from '../types';
|
|
|
|
|
|
|
|
|
|
interface Notification {
|
|
|
|
|
id: string;
|
|
|
|
|
type: string;
|
|
|
|
|
title: string;
|
|
|
|
|
content: string;
|
|
|
|
|
is_read: boolean;
|
|
|
|
|
created_at: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface CompanyRelationship {
|
|
|
|
|
id: string;
|
|
|
|
|
company: Company;
|
|
|
|
|
role: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const commonApi = {
|
|
|
|
|
getCompany: (id: string) =>
|
|
|
|
|
http.get<Company>(`/common/companies/${id}`).then(r => r.data),
|
|
|
|
|
|
|
|
|
|
listRelationships: () =>
|
|
|
|
|
http.get<CompanyRelationship[]>('/common/companies').then(r => r.data),
|
|
|
|
|
|
|
|
|
|
listMembers: () =>
|
|
|
|
|
http.get<(CompanyMember & { profile: Profile })[]>('/common/members').then(r => r.data),
|
|
|
|
|
|
|
|
|
|
createMember: (data: { username: string; password: string; display_name: string; phone?: string }) =>
|
|
|
|
|
http.post<CompanyMember>('/common/members', data).then(r => r.data),
|
|
|
|
|
|
|
|
|
|
deleteMember: (id: string) =>
|
|
|
|
|
http.delete(`/common/members/${id}`),
|
|
|
|
|
|
|
|
|
|
listNotifications: () =>
|
|
|
|
|
http.get<Notification[]>('/common/notifications').then(r => r.data),
|
|
|
|
|
|
|
|
|
|
markNotificationRead: (id: string) =>
|
|
|
|
|
http.patch(`/common/notifications/${id}`, { is_read: true }),
|
|
|
|
|
|
2026-06-30 07:15:26 +08:00
|
|
|
createShareLink: (data: { resource_type: string; resource_id: string }) =>
|
refactor: replace Supabase SDK with self-hosted REST API client layer
WHY: migrating from Supabase BaaS to self-hosted iloom backend
(Go microservices) deployed on K3s. Supabase client and realtime
subscriptions no longer applicable.
HOW:
- add src/api/ layer (client.ts, auth.ts, purchaser.ts, textile.ts,
washing.ts, websocket.ts) targeting iloom-gateway REST endpoints
- rewrite all hooks (usePlanData, useInventoryData, useDashboardData,
useRealtime, etc.) to use new API client instead of Supabase queries
- rewrite all page/component data fetching and mutations accordingly
- delete src/supabase/client.ts, remove @supabase/supabase-js dep
- add Dockerfile (multi-stage node build + nginx) and nginx.conf
with reverse proxy to iloom-gateway for /api/ and /ws/ routes
- adjust webpack.config.js for API_URL environment variable injection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-14 12:38:47 +08:00
|
|
|
http.post<{ code: string }>('/common/share-links', data).then(r => r.data),
|
|
|
|
|
|
|
|
|
|
getShareLink: (code: string) =>
|
|
|
|
|
http.get<unknown>(`/common/share-links/${code}`).then(r => r.data),
|
|
|
|
|
|
|
|
|
|
submitFeedback: (data: { content: string }) =>
|
|
|
|
|
http.post('/common/feedback', data),
|
2026-06-30 16:27:17 +08:00
|
|
|
|
|
|
|
|
uploadFile: async (file: File, bucket: string, pathPrefix: string): Promise<string> => {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
formData.append('bucket', bucket);
|
|
|
|
|
formData.append('path_prefix', pathPrefix);
|
|
|
|
|
|
2026-06-30 20:35:08 +08:00
|
|
|
if (!getAccessToken()) {
|
|
|
|
|
const { authApi } = await import('./auth');
|
|
|
|
|
try { await authApi.refresh(); } catch { /* will fail on upload */ }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const doUpload = async () => {
|
|
|
|
|
const token = getAccessToken();
|
|
|
|
|
const headers: Record<string, string> = {};
|
|
|
|
|
if (token) headers['Authorization'] = `Bearer ${token}`;
|
|
|
|
|
|
|
|
|
|
return fetch('/api/v1/common/upload', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers,
|
|
|
|
|
body: formData,
|
|
|
|
|
credentials: 'include',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let res = await doUpload();
|
|
|
|
|
|
|
|
|
|
if (res.status === 401) {
|
|
|
|
|
const { authApi } = await import('./auth');
|
|
|
|
|
try {
|
|
|
|
|
await authApi.refresh();
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error('auth expired');
|
|
|
|
|
}
|
|
|
|
|
res = await doUpload();
|
|
|
|
|
}
|
2026-06-30 16:27:17 +08:00
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
throw new Error('upload failed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
if (json.code !== 0) {
|
|
|
|
|
throw new Error(json.message || 'upload failed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return json.data?.url || '';
|
|
|
|
|
},
|
refactor: replace Supabase SDK with self-hosted REST API client layer
WHY: migrating from Supabase BaaS to self-hosted iloom backend
(Go microservices) deployed on K3s. Supabase client and realtime
subscriptions no longer applicable.
HOW:
- add src/api/ layer (client.ts, auth.ts, purchaser.ts, textile.ts,
washing.ts, websocket.ts) targeting iloom-gateway REST endpoints
- rewrite all hooks (usePlanData, useInventoryData, useDashboardData,
useRealtime, etc.) to use new API client instead of Supabase queries
- rewrite all page/component data fetching and mutations accordingly
- delete src/supabase/client.ts, remove @supabase/supabase-js dep
- add Dockerfile (multi-stage node build + nginx) and nginx.conf
with reverse proxy to iloom-gateway for /api/ and /ws/ routes
- adjust webpack.config.js for API_URL environment variable injection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-14 12:38:47 +08:00
|
|
|
};
|