mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
chore: move widget source into sidecar repo (widget-src/)
Widget builds from widget-src/ → public/widget.js Vite outDir updated to ../public .gitignore excludes node_modules Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
57
widget-src/src/api.ts
Normal file
57
widget-src/src/api.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { WidgetConfig, Doctor, TimeSlot } from './types';
|
||||
|
||||
let baseUrl = '';
|
||||
let widgetKey = '';
|
||||
|
||||
export const initApi = (url: string, key: string) => {
|
||||
baseUrl = url;
|
||||
widgetKey = key;
|
||||
};
|
||||
|
||||
const headers = () => ({
|
||||
'Content-Type': 'application/json',
|
||||
'X-Widget-Key': widgetKey,
|
||||
});
|
||||
|
||||
export const fetchInit = async (): Promise<WidgetConfig> => {
|
||||
const res = await fetch(`${baseUrl}/api/widget/init?key=${widgetKey}`);
|
||||
if (!res.ok) throw new Error('Widget init failed');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const fetchDoctors = async (): Promise<Doctor[]> => {
|
||||
const res = await fetch(`${baseUrl}/api/widget/doctors?key=${widgetKey}`);
|
||||
if (!res.ok) throw new Error('Failed to load doctors');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const fetchSlots = async (doctorId: string, date: string): Promise<TimeSlot[]> => {
|
||||
const res = await fetch(`${baseUrl}/api/widget/slots?key=${widgetKey}&doctorId=${doctorId}&date=${date}`);
|
||||
if (!res.ok) throw new Error('Failed to load slots');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const submitBooking = async (data: any): Promise<{ appointmentId: string; reference: string }> => {
|
||||
const res = await fetch(`${baseUrl}/api/widget/book?key=${widgetKey}`, {
|
||||
method: 'POST', headers: headers(), body: JSON.stringify(data),
|
||||
});
|
||||
if (!res.ok) throw new Error('Booking failed');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const submitLead = async (data: any): Promise<{ leadId: string }> => {
|
||||
const res = await fetch(`${baseUrl}/api/widget/lead?key=${widgetKey}`, {
|
||||
method: 'POST', headers: headers(), body: JSON.stringify(data),
|
||||
});
|
||||
if (!res.ok) throw new Error('Submission failed');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const streamChat = async (messages: any[], captchaToken?: string): Promise<ReadableStream> => {
|
||||
const res = await fetch(`${baseUrl}/api/widget/chat?key=${widgetKey}`, {
|
||||
method: 'POST', headers: headers(),
|
||||
body: JSON.stringify({ messages, captchaToken }),
|
||||
});
|
||||
if (!res.ok || !res.body) throw new Error('Chat failed');
|
||||
return res.body;
|
||||
};
|
||||
Reference in New Issue
Block a user