@upsnap/strapi 1.0.10 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -25
- package/dist/admin/{App-BIxhBt5_.mjs → App-QKoGSuNi.mjs} +60 -303
- package/dist/admin/{App-CH5fBeNI.js → App-l5dYTPZP.js} +221 -465
- package/dist/admin/index-BWyzuEFm.js +344 -0
- package/dist/admin/index-Ct7siGlB.mjs +343 -0
- package/dist/admin/index.js +2 -63
- package/dist/admin/index.mjs +2 -63
- package/dist/server/index.js +230 -76
- package/dist/server/index.mjs +228 -76
- package/dist/server/src/index.d.ts +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
+
const icons = require("@strapi/icons");
|
|
6
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
7
|
+
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
8
|
+
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
9
|
+
const v = glob[path];
|
|
10
|
+
if (v) {
|
|
11
|
+
return typeof v === "function" ? v() : Promise.resolve(v);
|
|
12
|
+
}
|
|
13
|
+
return new Promise((_, reject) => {
|
|
14
|
+
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
|
15
|
+
reject.bind(
|
|
16
|
+
null,
|
|
17
|
+
new Error(
|
|
18
|
+
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const PLUGIN_ID = "upsnap";
|
|
25
|
+
const STORAGE_KEY = "selectedMonitor";
|
|
26
|
+
function getUserData() {
|
|
27
|
+
if (typeof window === "undefined") return null;
|
|
28
|
+
try {
|
|
29
|
+
const userDataString = localStorage.getItem("userDetails");
|
|
30
|
+
if (!userDataString) return null;
|
|
31
|
+
const userData = JSON.parse(userDataString);
|
|
32
|
+
return userData;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Error parsing userData from localStorage:", error);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function getUserDetailsCached(forceFetchFromMicroservice = false) {
|
|
39
|
+
if (typeof window === "undefined") return null;
|
|
40
|
+
try {
|
|
41
|
+
const userDetailsString = localStorage.getItem("userDetails");
|
|
42
|
+
if (!userDetailsString) return null;
|
|
43
|
+
if (!forceFetchFromMicroservice) {
|
|
44
|
+
try {
|
|
45
|
+
const cached = JSON.parse(userDetailsString);
|
|
46
|
+
if (cached.updated_at) {
|
|
47
|
+
const cachedTime = Date.parse(cached.updated_at);
|
|
48
|
+
if (!isNaN(cachedTime)) {
|
|
49
|
+
const ageMs = Date.now() - cachedTime;
|
|
50
|
+
if (ageMs < 5 * 60 * 1e3) {
|
|
51
|
+
return cached;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error("Error parsing cached user details:", e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const data = await getUserDetails();
|
|
60
|
+
if (!data) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
setUserDetails(data);
|
|
64
|
+
return data;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("Error parsing userDetails from localStorage:", error);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function setUserDetails(details) {
|
|
71
|
+
if (typeof window === "undefined") return;
|
|
72
|
+
try {
|
|
73
|
+
const toStore = { ...details, updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
74
|
+
localStorage.setItem("userDetails", JSON.stringify(toStore));
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("Error storing userDetails in localStorage:", error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const clearAllStoredMonitors = () => {
|
|
80
|
+
if (typeof window === "undefined") return;
|
|
81
|
+
Object.keys(localStorage).forEach((key) => {
|
|
82
|
+
if (key.startsWith(`${STORAGE_KEY}`)) {
|
|
83
|
+
localStorage.removeItem(key);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
const request = async (url, options = {}) => {
|
|
88
|
+
const response = await axios__default.default({
|
|
89
|
+
url: `/upsnap${url}`,
|
|
90
|
+
...options
|
|
91
|
+
});
|
|
92
|
+
if (options?.responseType === "blob") {
|
|
93
|
+
return response;
|
|
94
|
+
}
|
|
95
|
+
return response.data;
|
|
96
|
+
};
|
|
97
|
+
const formatDate = (dateString) => {
|
|
98
|
+
const date = new Date(dateString);
|
|
99
|
+
if (isNaN(date.getTime())) {
|
|
100
|
+
return "N/A";
|
|
101
|
+
}
|
|
102
|
+
return date.toLocaleString(void 0, {
|
|
103
|
+
year: "numeric",
|
|
104
|
+
month: "2-digit",
|
|
105
|
+
day: "2-digit",
|
|
106
|
+
hour: "2-digit",
|
|
107
|
+
minute: "2-digit",
|
|
108
|
+
second: "2-digit",
|
|
109
|
+
hour12: false
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const formatTitleToUppercase = (title) => {
|
|
113
|
+
const words = title.split("_");
|
|
114
|
+
const capitalizedWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1));
|
|
115
|
+
return capitalizedWords.join(" ");
|
|
116
|
+
};
|
|
117
|
+
const getRangeTimestamps = (range) => {
|
|
118
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
119
|
+
const ranges = {
|
|
120
|
+
last_hour: 60 * 60,
|
|
121
|
+
last_24_hours: 60 * 60 * 24,
|
|
122
|
+
last_7_days: 60 * 60 * 24 * 7,
|
|
123
|
+
last_30_days: 60 * 60 * 24 * 30,
|
|
124
|
+
last_year: 60 * 60 * 24 * 365
|
|
125
|
+
};
|
|
126
|
+
const duration = ranges[range];
|
|
127
|
+
return {
|
|
128
|
+
start: now - duration,
|
|
129
|
+
end: now
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const formatCheckType = (key) => {
|
|
133
|
+
if (!key) return "";
|
|
134
|
+
const k = String(key).toLowerCase().trim();
|
|
135
|
+
const exceptions = ["ssl"];
|
|
136
|
+
if (exceptions.includes(k)) return k.toUpperCase();
|
|
137
|
+
const parts = k.split("_").filter(Boolean);
|
|
138
|
+
return parts.map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join(" ");
|
|
139
|
+
};
|
|
140
|
+
function formatDateTime(isoTimestamp) {
|
|
141
|
+
if (!isoTimestamp) return "-";
|
|
142
|
+
const date = new Date(isoTimestamp);
|
|
143
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
144
|
+
dateStyle: "medium",
|
|
145
|
+
timeStyle: "short"
|
|
146
|
+
}).format(date);
|
|
147
|
+
}
|
|
148
|
+
const getUserDetails = async () => {
|
|
149
|
+
try {
|
|
150
|
+
const result = await request("/user/details", {
|
|
151
|
+
method: "GET"
|
|
152
|
+
});
|
|
153
|
+
if (!result || result?.userDetailsData?.status !== "success") {
|
|
154
|
+
console.error("Failed to fetch user details");
|
|
155
|
+
} else {
|
|
156
|
+
setUserDetails(result?.userDetailsData.data);
|
|
157
|
+
return result?.userDetailsData.data;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("Error while fetching user details ", error);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
async function fetchMonitorSettings(monitorId) {
|
|
166
|
+
try {
|
|
167
|
+
const result = await request(`/monitor/settings/${monitorId}`);
|
|
168
|
+
if (!result) {
|
|
169
|
+
console.error("Failed to fetch monitor settings");
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
if (result?.monitorSettingsData?.status === "success" && result?.monitorSettingsData?.data) {
|
|
173
|
+
return {
|
|
174
|
+
monitor_id: result.monitorSettingsData.data.monitor_id,
|
|
175
|
+
settings: result.monitorSettingsData.data.settings
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
console.error("Invalid response from monitor settings API:", result);
|
|
179
|
+
return null;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error("Error fetching monitor settings:", error);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function settingsToConfig(settings) {
|
|
186
|
+
return {
|
|
187
|
+
meta: settings.meta,
|
|
188
|
+
services: settings.services
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
async function setPrimaryMonitorId(monitorId) {
|
|
192
|
+
try {
|
|
193
|
+
const result = await request(`/settings/set-primary-monitor-id`, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
data: { monitorId }
|
|
196
|
+
});
|
|
197
|
+
if (!result) return false;
|
|
198
|
+
if (result?.ok) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error("Error setting primary monitor ID:", error);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function getPrimaryMonitorId() {
|
|
208
|
+
try {
|
|
209
|
+
const result = await request(`/settings/get-primary-monitor-id`, {
|
|
210
|
+
method: "GET"
|
|
211
|
+
});
|
|
212
|
+
if (!result) return null;
|
|
213
|
+
if (result?.primaryMonitorId) {
|
|
214
|
+
return result.primaryMonitorId;
|
|
215
|
+
}
|
|
216
|
+
console.error("Failed to get primary monitor ID:", result);
|
|
217
|
+
return null;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error("Error getting primary monitor ID:", error);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async function handleLogout() {
|
|
224
|
+
try {
|
|
225
|
+
await setPrimaryMonitorId("");
|
|
226
|
+
const res = await request("/settings", {
|
|
227
|
+
method: "POST",
|
|
228
|
+
data: { token: null, logOut: true }
|
|
229
|
+
});
|
|
230
|
+
if (res.ok) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
} catch (err) {
|
|
235
|
+
console.log("Error while logging out ", err);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const fetchRegionsData = async () => {
|
|
240
|
+
try {
|
|
241
|
+
const result = await request(`/regions`);
|
|
242
|
+
if (!result) return [];
|
|
243
|
+
if (result?.regionsData?.status === "success" && Array.isArray(result?.regionsData?.data)) {
|
|
244
|
+
return result?.regionsData?.data;
|
|
245
|
+
}
|
|
246
|
+
return [];
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.error("Error fetching regions:", error);
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const fetchTags = async (setIsLoading, setTags) => {
|
|
253
|
+
setIsLoading(true);
|
|
254
|
+
try {
|
|
255
|
+
const result = await request("/tags", {
|
|
256
|
+
method: "GET"
|
|
257
|
+
});
|
|
258
|
+
if (!result?.tagsData) {
|
|
259
|
+
throw new Error("Failed to fetch tags");
|
|
260
|
+
}
|
|
261
|
+
setTags(result?.tagsData?.data);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error("Error fetching tags:", error);
|
|
264
|
+
} finally {
|
|
265
|
+
setIsLoading(false);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const Initializer = ({ setPlugin }) => {
|
|
269
|
+
const ref = React.useRef(setPlugin);
|
|
270
|
+
React.useEffect(() => {
|
|
271
|
+
ref.current(PLUGIN_ID);
|
|
272
|
+
const trackUser = async () => {
|
|
273
|
+
try {
|
|
274
|
+
const payload = {
|
|
275
|
+
browser: navigator.userAgent,
|
|
276
|
+
os: navigator.userAgentData?.platform || navigator.platform || "Unknown",
|
|
277
|
+
language: navigator.language,
|
|
278
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
279
|
+
client_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
280
|
+
};
|
|
281
|
+
await request("/track-user-data", {
|
|
282
|
+
method: "POST",
|
|
283
|
+
data: payload
|
|
284
|
+
});
|
|
285
|
+
} catch (error) {
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
trackUser();
|
|
289
|
+
}, []);
|
|
290
|
+
return null;
|
|
291
|
+
};
|
|
292
|
+
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.ChartCircle, {});
|
|
293
|
+
const index = {
|
|
294
|
+
register(app) {
|
|
295
|
+
app.addMenuLink({
|
|
296
|
+
to: `plugins/${PLUGIN_ID}`,
|
|
297
|
+
icon: PluginIcon,
|
|
298
|
+
intlLabel: {
|
|
299
|
+
id: `${PLUGIN_ID}.plugin.name`,
|
|
300
|
+
defaultMessage: PLUGIN_ID.slice(0, 1).toUpperCase() + PLUGIN_ID.slice(1)
|
|
301
|
+
},
|
|
302
|
+
Component: async () => {
|
|
303
|
+
const { App } = await Promise.resolve().then(() => require("./App-l5dYTPZP.js"));
|
|
304
|
+
return App;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
app.registerPlugin({
|
|
308
|
+
id: PLUGIN_ID,
|
|
309
|
+
initializer: Initializer,
|
|
310
|
+
isReady: false,
|
|
311
|
+
name: PLUGIN_ID
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
async registerTrads({ locales }) {
|
|
315
|
+
return Promise.all(
|
|
316
|
+
locales.map(async (locale) => {
|
|
317
|
+
try {
|
|
318
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => require("./en-B4KWt_jN.js")) }), `./translations/${locale}.json`, 3);
|
|
319
|
+
return { data, locale };
|
|
320
|
+
} catch {
|
|
321
|
+
return { data: {}, locale };
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
exports.clearAllStoredMonitors = clearAllStoredMonitors;
|
|
328
|
+
exports.fetchMonitorSettings = fetchMonitorSettings;
|
|
329
|
+
exports.fetchRegionsData = fetchRegionsData;
|
|
330
|
+
exports.fetchTags = fetchTags;
|
|
331
|
+
exports.formatCheckType = formatCheckType;
|
|
332
|
+
exports.formatDate = formatDate;
|
|
333
|
+
exports.formatDateTime = formatDateTime;
|
|
334
|
+
exports.formatTitleToUppercase = formatTitleToUppercase;
|
|
335
|
+
exports.getPrimaryMonitorId = getPrimaryMonitorId;
|
|
336
|
+
exports.getRangeTimestamps = getRangeTimestamps;
|
|
337
|
+
exports.getUserData = getUserData;
|
|
338
|
+
exports.getUserDetails = getUserDetails;
|
|
339
|
+
exports.getUserDetailsCached = getUserDetailsCached;
|
|
340
|
+
exports.handleLogout = handleLogout;
|
|
341
|
+
exports.index = index;
|
|
342
|
+
exports.request = request;
|
|
343
|
+
exports.setPrimaryMonitorId = setPrimaryMonitorId;
|
|
344
|
+
exports.settingsToConfig = settingsToConfig;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { ChartCircle } from "@strapi/icons";
|
|
5
|
+
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
6
|
+
const v = glob[path];
|
|
7
|
+
if (v) {
|
|
8
|
+
return typeof v === "function" ? v() : Promise.resolve(v);
|
|
9
|
+
}
|
|
10
|
+
return new Promise((_, reject) => {
|
|
11
|
+
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
|
12
|
+
reject.bind(
|
|
13
|
+
null,
|
|
14
|
+
new Error(
|
|
15
|
+
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const PLUGIN_ID = "upsnap";
|
|
22
|
+
const STORAGE_KEY = "selectedMonitor";
|
|
23
|
+
function getUserData() {
|
|
24
|
+
if (typeof window === "undefined") return null;
|
|
25
|
+
try {
|
|
26
|
+
const userDataString = localStorage.getItem("userDetails");
|
|
27
|
+
if (!userDataString) return null;
|
|
28
|
+
const userData = JSON.parse(userDataString);
|
|
29
|
+
return userData;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error("Error parsing userData from localStorage:", error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function getUserDetailsCached(forceFetchFromMicroservice = false) {
|
|
36
|
+
if (typeof window === "undefined") return null;
|
|
37
|
+
try {
|
|
38
|
+
const userDetailsString = localStorage.getItem("userDetails");
|
|
39
|
+
if (!userDetailsString) return null;
|
|
40
|
+
if (!forceFetchFromMicroservice) {
|
|
41
|
+
try {
|
|
42
|
+
const cached = JSON.parse(userDetailsString);
|
|
43
|
+
if (cached.updated_at) {
|
|
44
|
+
const cachedTime = Date.parse(cached.updated_at);
|
|
45
|
+
if (!isNaN(cachedTime)) {
|
|
46
|
+
const ageMs = Date.now() - cachedTime;
|
|
47
|
+
if (ageMs < 5 * 60 * 1e3) {
|
|
48
|
+
return cached;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error("Error parsing cached user details:", e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const data = await getUserDetails();
|
|
57
|
+
if (!data) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
setUserDetails(data);
|
|
61
|
+
return data;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Error parsing userDetails from localStorage:", error);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function setUserDetails(details) {
|
|
68
|
+
if (typeof window === "undefined") return;
|
|
69
|
+
try {
|
|
70
|
+
const toStore = { ...details, updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
71
|
+
localStorage.setItem("userDetails", JSON.stringify(toStore));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Error storing userDetails in localStorage:", error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const clearAllStoredMonitors = () => {
|
|
77
|
+
if (typeof window === "undefined") return;
|
|
78
|
+
Object.keys(localStorage).forEach((key) => {
|
|
79
|
+
if (key.startsWith(`${STORAGE_KEY}`)) {
|
|
80
|
+
localStorage.removeItem(key);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const request = async (url, options = {}) => {
|
|
85
|
+
const response = await axios({
|
|
86
|
+
url: `/upsnap${url}`,
|
|
87
|
+
...options
|
|
88
|
+
});
|
|
89
|
+
if (options?.responseType === "blob") {
|
|
90
|
+
return response;
|
|
91
|
+
}
|
|
92
|
+
return response.data;
|
|
93
|
+
};
|
|
94
|
+
const formatDate = (dateString) => {
|
|
95
|
+
const date = new Date(dateString);
|
|
96
|
+
if (isNaN(date.getTime())) {
|
|
97
|
+
return "N/A";
|
|
98
|
+
}
|
|
99
|
+
return date.toLocaleString(void 0, {
|
|
100
|
+
year: "numeric",
|
|
101
|
+
month: "2-digit",
|
|
102
|
+
day: "2-digit",
|
|
103
|
+
hour: "2-digit",
|
|
104
|
+
minute: "2-digit",
|
|
105
|
+
second: "2-digit",
|
|
106
|
+
hour12: false
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const formatTitleToUppercase = (title) => {
|
|
110
|
+
const words = title.split("_");
|
|
111
|
+
const capitalizedWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1));
|
|
112
|
+
return capitalizedWords.join(" ");
|
|
113
|
+
};
|
|
114
|
+
const getRangeTimestamps = (range) => {
|
|
115
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
116
|
+
const ranges = {
|
|
117
|
+
last_hour: 60 * 60,
|
|
118
|
+
last_24_hours: 60 * 60 * 24,
|
|
119
|
+
last_7_days: 60 * 60 * 24 * 7,
|
|
120
|
+
last_30_days: 60 * 60 * 24 * 30,
|
|
121
|
+
last_year: 60 * 60 * 24 * 365
|
|
122
|
+
};
|
|
123
|
+
const duration = ranges[range];
|
|
124
|
+
return {
|
|
125
|
+
start: now - duration,
|
|
126
|
+
end: now
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const formatCheckType = (key) => {
|
|
130
|
+
if (!key) return "";
|
|
131
|
+
const k = String(key).toLowerCase().trim();
|
|
132
|
+
const exceptions = ["ssl"];
|
|
133
|
+
if (exceptions.includes(k)) return k.toUpperCase();
|
|
134
|
+
const parts = k.split("_").filter(Boolean);
|
|
135
|
+
return parts.map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join(" ");
|
|
136
|
+
};
|
|
137
|
+
function formatDateTime(isoTimestamp) {
|
|
138
|
+
if (!isoTimestamp) return "-";
|
|
139
|
+
const date = new Date(isoTimestamp);
|
|
140
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
141
|
+
dateStyle: "medium",
|
|
142
|
+
timeStyle: "short"
|
|
143
|
+
}).format(date);
|
|
144
|
+
}
|
|
145
|
+
const getUserDetails = async () => {
|
|
146
|
+
try {
|
|
147
|
+
const result = await request("/user/details", {
|
|
148
|
+
method: "GET"
|
|
149
|
+
});
|
|
150
|
+
if (!result || result?.userDetailsData?.status !== "success") {
|
|
151
|
+
console.error("Failed to fetch user details");
|
|
152
|
+
} else {
|
|
153
|
+
setUserDetails(result?.userDetailsData.data);
|
|
154
|
+
return result?.userDetailsData.data;
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error("Error while fetching user details ", error);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
async function fetchMonitorSettings(monitorId) {
|
|
163
|
+
try {
|
|
164
|
+
const result = await request(`/monitor/settings/${monitorId}`);
|
|
165
|
+
if (!result) {
|
|
166
|
+
console.error("Failed to fetch monitor settings");
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
if (result?.monitorSettingsData?.status === "success" && result?.monitorSettingsData?.data) {
|
|
170
|
+
return {
|
|
171
|
+
monitor_id: result.monitorSettingsData.data.monitor_id,
|
|
172
|
+
settings: result.monitorSettingsData.data.settings
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
console.error("Invalid response from monitor settings API:", result);
|
|
176
|
+
return null;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error("Error fetching monitor settings:", error);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function settingsToConfig(settings) {
|
|
183
|
+
return {
|
|
184
|
+
meta: settings.meta,
|
|
185
|
+
services: settings.services
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async function setPrimaryMonitorId(monitorId) {
|
|
189
|
+
try {
|
|
190
|
+
const result = await request(`/settings/set-primary-monitor-id`, {
|
|
191
|
+
method: "POST",
|
|
192
|
+
data: { monitorId }
|
|
193
|
+
});
|
|
194
|
+
if (!result) return false;
|
|
195
|
+
if (result?.ok) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error("Error setting primary monitor ID:", error);
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async function getPrimaryMonitorId() {
|
|
205
|
+
try {
|
|
206
|
+
const result = await request(`/settings/get-primary-monitor-id`, {
|
|
207
|
+
method: "GET"
|
|
208
|
+
});
|
|
209
|
+
if (!result) return null;
|
|
210
|
+
if (result?.primaryMonitorId) {
|
|
211
|
+
return result.primaryMonitorId;
|
|
212
|
+
}
|
|
213
|
+
console.error("Failed to get primary monitor ID:", result);
|
|
214
|
+
return null;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.error("Error getting primary monitor ID:", error);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function handleLogout() {
|
|
221
|
+
try {
|
|
222
|
+
await setPrimaryMonitorId("");
|
|
223
|
+
const res = await request("/settings", {
|
|
224
|
+
method: "POST",
|
|
225
|
+
data: { token: null, logOut: true }
|
|
226
|
+
});
|
|
227
|
+
if (res.ok) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
} catch (err) {
|
|
232
|
+
console.log("Error while logging out ", err);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const fetchRegionsData = async () => {
|
|
237
|
+
try {
|
|
238
|
+
const result = await request(`/regions`);
|
|
239
|
+
if (!result) return [];
|
|
240
|
+
if (result?.regionsData?.status === "success" && Array.isArray(result?.regionsData?.data)) {
|
|
241
|
+
return result?.regionsData?.data;
|
|
242
|
+
}
|
|
243
|
+
return [];
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error("Error fetching regions:", error);
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const fetchTags = async (setIsLoading, setTags) => {
|
|
250
|
+
setIsLoading(true);
|
|
251
|
+
try {
|
|
252
|
+
const result = await request("/tags", {
|
|
253
|
+
method: "GET"
|
|
254
|
+
});
|
|
255
|
+
if (!result?.tagsData) {
|
|
256
|
+
throw new Error("Failed to fetch tags");
|
|
257
|
+
}
|
|
258
|
+
setTags(result?.tagsData?.data);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
console.error("Error fetching tags:", error);
|
|
261
|
+
} finally {
|
|
262
|
+
setIsLoading(false);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const Initializer = ({ setPlugin }) => {
|
|
266
|
+
const ref = useRef(setPlugin);
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
ref.current(PLUGIN_ID);
|
|
269
|
+
const trackUser = async () => {
|
|
270
|
+
try {
|
|
271
|
+
const payload = {
|
|
272
|
+
browser: navigator.userAgent,
|
|
273
|
+
os: navigator.userAgentData?.platform || navigator.platform || "Unknown",
|
|
274
|
+
language: navigator.language,
|
|
275
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
276
|
+
client_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
277
|
+
};
|
|
278
|
+
await request("/track-user-data", {
|
|
279
|
+
method: "POST",
|
|
280
|
+
data: payload
|
|
281
|
+
});
|
|
282
|
+
} catch (error) {
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
trackUser();
|
|
286
|
+
}, []);
|
|
287
|
+
return null;
|
|
288
|
+
};
|
|
289
|
+
const PluginIcon = () => /* @__PURE__ */ jsx(ChartCircle, {});
|
|
290
|
+
const index = {
|
|
291
|
+
register(app) {
|
|
292
|
+
app.addMenuLink({
|
|
293
|
+
to: `plugins/${PLUGIN_ID}`,
|
|
294
|
+
icon: PluginIcon,
|
|
295
|
+
intlLabel: {
|
|
296
|
+
id: `${PLUGIN_ID}.plugin.name`,
|
|
297
|
+
defaultMessage: PLUGIN_ID.slice(0, 1).toUpperCase() + PLUGIN_ID.slice(1)
|
|
298
|
+
},
|
|
299
|
+
Component: async () => {
|
|
300
|
+
const { App } = await import("./App-QKoGSuNi.mjs");
|
|
301
|
+
return App;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
app.registerPlugin({
|
|
305
|
+
id: PLUGIN_ID,
|
|
306
|
+
initializer: Initializer,
|
|
307
|
+
isReady: false,
|
|
308
|
+
name: PLUGIN_ID
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
async registerTrads({ locales }) {
|
|
312
|
+
return Promise.all(
|
|
313
|
+
locales.map(async (locale) => {
|
|
314
|
+
try {
|
|
315
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("./en-Byx4XI2L.mjs") }), `./translations/${locale}.json`, 3);
|
|
316
|
+
return { data, locale };
|
|
317
|
+
} catch {
|
|
318
|
+
return { data: {}, locale };
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
export {
|
|
325
|
+
getUserDetailsCached as a,
|
|
326
|
+
getUserDetails as b,
|
|
327
|
+
getUserData as c,
|
|
328
|
+
formatTitleToUppercase as d,
|
|
329
|
+
fetchMonitorSettings as e,
|
|
330
|
+
fetchTags as f,
|
|
331
|
+
getPrimaryMonitorId as g,
|
|
332
|
+
settingsToConfig as h,
|
|
333
|
+
clearAllStoredMonitors as i,
|
|
334
|
+
handleLogout as j,
|
|
335
|
+
formatDate as k,
|
|
336
|
+
formatCheckType as l,
|
|
337
|
+
getRangeTimestamps as m,
|
|
338
|
+
formatDateTime as n,
|
|
339
|
+
fetchRegionsData as o,
|
|
340
|
+
index as p,
|
|
341
|
+
request as r,
|
|
342
|
+
setPrimaryMonitorId as s
|
|
343
|
+
};
|