PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 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 All 128 releases
extendify / src / Shared / api / digest.js

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

82 lines 2.3 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 // Retried steps re-report the same failure; one site sent 89k rows before this.
5 const sent = new Set();
6
7 const describeError = (e) => {
8 if (!e) return { message: 'Unknown error', name: 'Error', stack: '' };
9 if (e instanceof Response) {
10 return {
11 message: `HTTP ${e.status}: ${e.statusText}`,
12 name: 'FetchError',
13 stack: '',
14 };
15 }
16 return {
17 message:
18 e?.response?.statusText ||
19 e?.response?.message ||
20 e?.statusText ||
21 e?.message ||
22 (typeof e === 'string' ? e : 'Unknown error'),
23 name: e?.name || 'Error',
24 // WordPress localizes the message; the code is what groups it.
25 code: e?.code,
26 };
27 };
28
29 export const digest = ({ type = 'error', error, details = {} } = {}) => {
30 if (Boolean(reqDataBasics?.devbuild) === true) return;
31
32 const errorData = describeError(error);
33 const key = JSON.stringify([type, details, errorData]);
34 if (sent.has(key)) return;
35 sent.add(key);
36
37 const extra = {
38 userAgent: window?.navigator?.userAgent,
39 vendor: window?.navigator?.vendor || 'unknown',
40 platform:
41 window?.navigator?.userAgentData?.platform ||
42 window?.navigator?.platform ||
43 'unknown',
44 mobile: window?.navigator?.userAgentData?.mobile,
45 width: window.innerWidth,
46 height: window.innerHeight,
47 screenHeight: window.screen.height,
48 screenWidth: window.screen.width,
49 orientation: window.screen.orientation?.type,
50 touchSupport: 'ontouchstart' in window || navigator.maxTouchPoints > 0,
51 };
52
53 const payload = JSON.stringify({
54 ...reqDataBasics,
55 siteProfile: {
56 type: reqDataBasics?.siteProfile?.type,
57 title: reqDataBasics?.siteProfile?.title,
58 description: reqDataBasics?.siteProfile?.description,
59 descriptionRaw: reqDataBasics?.siteProfile?.descriptionRaw,
60 objective: reqDataBasics?.siteProfile?.objective,
61 category: reqDataBasics?.siteProfile?.category,
62 structure: reqDataBasics?.siteProfile?.structure,
63 imageSearchTerms: reqDataBasics?.siteProfile?.imageSearchTerms,
64 },
65 ...details,
66 error: errorData,
67 type,
68 extra,
69 });
70
71 return fetch(`${AI_HOST}/api/digest`, {
72 method: 'POST',
73 headers: {
74 'Content-Type': 'application/json',
75 Accept: 'application/json',
76 'X-Extendify': 'true',
77 },
78 body: payload,
79 keepalive: true,
80 }).catch(() => {});
81 };
82