Add insights
This commit is contained in:
parent
49ea5f3e86
commit
b445961ad5
1 changed files with 94 additions and 1 deletions
27
src/helper/handle-insights.ts
Normal file
27
src/helper/handle-insights.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const baseUri = 'https://insights.decla.red';
|
||||
const type = 'sdf-2d-demo';
|
||||
|
||||
export const handleInsights = async (initialData: any): Promise<(data: any) => void> => {
|
||||
const sessionId = await createSession(initialData);
|
||||
return (data) => createFrame(sessionId, data);
|
||||
};
|
||||
|
||||
const createSession = async (data: any): Promise<string> => {
|
||||
const response = await sendPostRequest(`${baseUri}/${type}/sessions/`, data);
|
||||
const { sessionId } = await response.json();
|
||||
return sessionId;
|
||||
};
|
||||
|
||||
const createFrame = async (sessionId: string, data: any): Promise<unknown> =>
|
||||
await sendPostRequest(`${baseUri}/${type}/sessions/${sessionId}`, data);
|
||||
|
||||
const sendPostRequest = async (uri: string, data: any): Promise<Response> =>
|
||||
await fetch(uri, {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
redirect: 'follow',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
Loading…
Reference in a new issue