forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit-app.ts
More file actions
84 lines (74 loc) · 1.99 KB
/
Copy pathsubmit-app.ts
File metadata and controls
84 lines (74 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use server';
import envConfig from '@/src/constants/envConfig';
export interface ExternalIntegration {
triggers_on: string;
webhook_url: string;
setup_completed_url: string;
setup_instructions_file_path: string;
app_home_url: string;
auth_steps: Array<{
url: string;
name: string;
}>;
}
export interface ProactiveNotification {
scopes: string[];
}
export interface AppSubmissionData {
name: string;
description: string;
capabilities: string[];
deleted: boolean;
uid: string;
category: string;
private: boolean;
is_paid: boolean;
price: number;
payment_plan: string | null;
thumbnails: string[];
external_integration?: ExternalIntegration;
chat_prompt?: string;
memory_prompt?: string;
proactive_notification?: ProactiveNotification;
}
export interface SubmitAppResponse {
id: string;
name: string;
[key: string]: unknown;
}
export default async function submitApp(
formData: FormData,
): Promise<SubmitAppResponse | null> {
const apiUrl = envConfig.API_URL || 'http://localhost:8000';
try {
// Get token from formData
const token = formData.get('token') as string;
// Remove token from formData before sending to API
const apiFormData = new FormData();
Array.from(formData.entries()).forEach(([key, value]) => {
if (key !== 'token') {
apiFormData.append(key, value);
}
});
const response = await fetch(`${apiUrl}/v1/apps`, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
body: apiFormData,
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({
detail: 'Failed to parse error response',
}));
console.error('Failed to submit app:', response.status, errorData);
throw new Error(
errorData.detail || `HTTP ${response.status}: ${response.statusText}`,
);
}
return await response.json();
} catch (error) {
console.error('Error submitting app:', error);
throw error;
}
}