PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / api / digest.js

digest.js in Extendify trunk, at src/Shared/api/digest.js

72 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { AI_HOST } from '@constants';
2 import { reqDataBasics } from '@shared/lib/data';
3
4 // ctx, can be any extra data you want to pass to the digest for better insights, e.g. { function: 'handleSiteLogo' }
5 export const digest = ({ type = 'error', error, details = {} } = {}) => {
6 if (Boolean(reqDataBasics?.devbuild) === true) return;
7
8 const extra = {
9 userAgent: window?.navigator?.userAgent,
10 vendor: window?.navigator?.vendor || 'unknown',
11 platform:
12 window?.navigator?.userAgentData?.platform ||
13 window?.navigator?.platform ||
14 'unknown',
15 mobile: window?.navigator?.userAgentData?.mobile,
16 width: window.innerWidth,
17 height: window.innerHeight,
18 screenHeight: window.screen.height,
19 screenWidth: window.screen.width,
20 orientation: window.screen.orientation?.type,
21 touchSupport: 'ontouchstart' in window || navigator.maxTouchPoints > 0,
22 };
23
24 const errorData = ((e) => {
25 if (!e) return { message: 'Unknown error', name: 'Error', stack: '' };
26 if (e instanceof Response)
27 return {
28 message: `HTTP ${e.status}: ${e.statusText}`,
29 name: 'FetchError',
30 stack: '',
31 };
32 return {
33 message:
34 e?.response?.statusText ||
35 e?.response?.message ||
36 e?.statusText ||
37 e?.message ||
38 (typeof e === 'string' ? e : 'Unknown error'),
39 name: e?.name || 'Error',
40 };
41 })(error);
42
43 const payload = JSON.stringify({
44 ...reqDataBasics,
45 siteProfile: {
46 type: reqDataBasics?.siteProfile?.type,
47 title: reqDataBasics?.siteProfile?.title,
48 description: reqDataBasics?.siteProfile?.description,
49 descriptionRaw: reqDataBasics?.siteProfile?.descriptionRaw,
50 objective: reqDataBasics?.siteProfile?.objective,
51 category: reqDataBasics?.siteProfile?.category,
52 structure: reqDataBasics?.siteProfile?.structure,
53 imageSearchTerms: reqDataBasics?.siteProfile?.imageSearchTerms,
54 },
55 ...details,
56 error: errorData,
57 type,
58 extra,
59 });
60
61 return fetch(`${AI_HOST}/api/digest`, {
62 method: 'POST',
63 headers: {
64 'Content-Type': 'application/json',
65 Accept: 'application/json',
66 'X-Extendify': 'true',
67 },
68 body: payload,
69 keepalive: true,
70 }).catch(() => {});
71 };
72