@upsnap/strapi 1.0.11 → 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 +3 -0
- 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 +112 -27
- package/dist/server/index.mjs +110 -27
- package/dist/server/src/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/admin/index.js
CHANGED
|
@@ -1,65 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const icons = require("@strapi/icons");
|
|
6
|
-
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
7
|
-
const v = glob[path];
|
|
8
|
-
if (v) {
|
|
9
|
-
return typeof v === "function" ? v() : Promise.resolve(v);
|
|
10
|
-
}
|
|
11
|
-
return new Promise((_, reject) => {
|
|
12
|
-
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
|
13
|
-
reject.bind(
|
|
14
|
-
null,
|
|
15
|
-
new Error(
|
|
16
|
-
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
|
|
17
|
-
)
|
|
18
|
-
)
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const PLUGIN_ID = "upsnap";
|
|
23
|
-
const Initializer = ({ setPlugin }) => {
|
|
24
|
-
const ref = React.useRef(setPlugin);
|
|
25
|
-
React.useEffect(() => {
|
|
26
|
-
ref.current(PLUGIN_ID);
|
|
27
|
-
}, []);
|
|
28
|
-
return null;
|
|
29
|
-
};
|
|
30
|
-
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.ChartCircle, {});
|
|
31
|
-
const index = {
|
|
32
|
-
register(app) {
|
|
33
|
-
app.addMenuLink({
|
|
34
|
-
to: `plugins/${PLUGIN_ID}`,
|
|
35
|
-
icon: PluginIcon,
|
|
36
|
-
intlLabel: {
|
|
37
|
-
id: `${PLUGIN_ID}.plugin.name`,
|
|
38
|
-
defaultMessage: PLUGIN_ID.slice(0, 1).toUpperCase() + PLUGIN_ID.slice(1)
|
|
39
|
-
},
|
|
40
|
-
Component: async () => {
|
|
41
|
-
const { App } = await Promise.resolve().then(() => require("./App-CH5fBeNI.js"));
|
|
42
|
-
return App;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
app.registerPlugin({
|
|
46
|
-
id: PLUGIN_ID,
|
|
47
|
-
initializer: Initializer,
|
|
48
|
-
isReady: false,
|
|
49
|
-
name: PLUGIN_ID
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
async registerTrads({ locales }) {
|
|
53
|
-
return Promise.all(
|
|
54
|
-
locales.map(async (locale) => {
|
|
55
|
-
try {
|
|
56
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => require("./en-B4KWt_jN.js")) }), `./translations/${locale}.json`, 3);
|
|
57
|
-
return { data, locale };
|
|
58
|
-
} catch {
|
|
59
|
-
return { data: {}, locale };
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
exports.default = index;
|
|
3
|
+
const index = require("./index-BWyzuEFm.js");
|
|
4
|
+
exports.default = index.index;
|
package/dist/admin/index.mjs
CHANGED
|
@@ -1,65 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { ChartCircle } from "@strapi/icons";
|
|
4
|
-
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
5
|
-
const v = glob[path];
|
|
6
|
-
if (v) {
|
|
7
|
-
return typeof v === "function" ? v() : Promise.resolve(v);
|
|
8
|
-
}
|
|
9
|
-
return new Promise((_, reject) => {
|
|
10
|
-
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
|
11
|
-
reject.bind(
|
|
12
|
-
null,
|
|
13
|
-
new Error(
|
|
14
|
-
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
|
|
15
|
-
)
|
|
16
|
-
)
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
const PLUGIN_ID = "upsnap";
|
|
21
|
-
const Initializer = ({ setPlugin }) => {
|
|
22
|
-
const ref = useRef(setPlugin);
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
ref.current(PLUGIN_ID);
|
|
25
|
-
}, []);
|
|
26
|
-
return null;
|
|
27
|
-
};
|
|
28
|
-
const PluginIcon = () => /* @__PURE__ */ jsx(ChartCircle, {});
|
|
29
|
-
const index = {
|
|
30
|
-
register(app) {
|
|
31
|
-
app.addMenuLink({
|
|
32
|
-
to: `plugins/${PLUGIN_ID}`,
|
|
33
|
-
icon: PluginIcon,
|
|
34
|
-
intlLabel: {
|
|
35
|
-
id: `${PLUGIN_ID}.plugin.name`,
|
|
36
|
-
defaultMessage: PLUGIN_ID.slice(0, 1).toUpperCase() + PLUGIN_ID.slice(1)
|
|
37
|
-
},
|
|
38
|
-
Component: async () => {
|
|
39
|
-
const { App } = await import("./App-BIxhBt5_.mjs");
|
|
40
|
-
return App;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
app.registerPlugin({
|
|
44
|
-
id: PLUGIN_ID,
|
|
45
|
-
initializer: Initializer,
|
|
46
|
-
isReady: false,
|
|
47
|
-
name: PLUGIN_ID
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
async registerTrads({ locales }) {
|
|
51
|
-
return Promise.all(
|
|
52
|
-
locales.map(async (locale) => {
|
|
53
|
-
try {
|
|
54
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("./en-Byx4XI2L.mjs") }), `./translations/${locale}.json`, 3);
|
|
55
|
-
return { data, locale };
|
|
56
|
-
} catch {
|
|
57
|
-
return { data: {}, locale };
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
1
|
+
import { p } from "./index-Ct7siGlB.mjs";
|
|
63
2
|
export {
|
|
64
|
-
|
|
3
|
+
p as default
|
|
65
4
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
5
|
+
const crypto__default = /* @__PURE__ */ _interopDefault(crypto);
|
|
6
|
+
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
7
|
+
};
|
|
8
|
+
const destroy = ({ strapi: strapi2 }) => {
|
|
9
|
+
};
|
|
10
|
+
const register = ({ strapi: strapi2 }) => {
|
|
11
|
+
};
|
|
12
|
+
const config = {
|
|
13
|
+
default: {},
|
|
14
|
+
validator() {
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const contentTypes = {};
|
|
18
|
+
const controller = ({ strapi: strapi2 }) => ({
|
|
19
|
+
index(ctx) {
|
|
20
|
+
ctx.body = strapi2.plugin("upsnap").service("service").getWelcomeMessage();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
3
23
|
const BACKEND_URL = "https://api.upsnap.ai/v1";
|
|
24
|
+
const IP_API_BASE_URL = "https://ipapi.co";
|
|
4
25
|
const LIGHTHOUSE_CHECKS = ["performance", "accessibility", "bestPractices", "seo", "pwa"];
|
|
5
|
-
const version = "1.0.
|
|
26
|
+
const version = "1.0.14";
|
|
6
27
|
const repository = { "type": "git", "url": "https://github.com/Appfoster/upsnap-strapi" };
|
|
7
28
|
const keywords = [];
|
|
8
29
|
const type = "commonjs";
|
|
@@ -77,7 +98,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
|
77
98
|
headers: response.headers
|
|
78
99
|
};
|
|
79
100
|
},
|
|
80
|
-
async trackInstallation() {
|
|
101
|
+
async trackInstallation(userPayload) {
|
|
81
102
|
try {
|
|
82
103
|
const settings2 = await this.settingsStore.get();
|
|
83
104
|
if (settings2?.installationTracked) {
|
|
@@ -86,25 +107,67 @@ const service = ({ strapi: strapi2 }) => ({
|
|
|
86
107
|
const pluginVersion = packageJson.version;
|
|
87
108
|
const strapiVersion = strapi2.config.get("info.strapi");
|
|
88
109
|
const siteUrl = strapi2.config.get("server.url") || `http://${strapi2.config.get("server.host") || "localhost"}:${strapi2.config.get("server.port") || 1337}`;
|
|
110
|
+
const users = await strapi2.db.query("admin::user").findMany({
|
|
111
|
+
orderBy: { createdAt: "ASC" },
|
|
112
|
+
limit: 1
|
|
113
|
+
});
|
|
114
|
+
const firstUser = users?.[0];
|
|
115
|
+
const email = firstUser?.email || "";
|
|
116
|
+
const name2 = `${firstUser?.firstname || ""} ${firstUser?.lastname || ""}`.trim();
|
|
117
|
+
const phoneNumber = firstUser?.phoneNumber || firstUser?.phone || "";
|
|
118
|
+
const company = firstUser?.company || "";
|
|
119
|
+
const installId = settings2?.installId || crypto__default.default.randomUUID();
|
|
120
|
+
let finalDetails = {
|
|
121
|
+
version: pluginVersion,
|
|
122
|
+
site_url: siteUrl,
|
|
123
|
+
strapi_version: strapiVersion,
|
|
124
|
+
install_id: installId,
|
|
125
|
+
email,
|
|
126
|
+
name: name2,
|
|
127
|
+
phone_number: phoneNumber,
|
|
128
|
+
company
|
|
129
|
+
};
|
|
130
|
+
if (userPayload) {
|
|
131
|
+
finalDetails = { ...finalDetails, ...userPayload };
|
|
132
|
+
} else {
|
|
133
|
+
let ipAddress = "";
|
|
134
|
+
let country = "";
|
|
135
|
+
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
|
|
136
|
+
let browserOs = `Node.js ${process.version} / ${process.platform}`;
|
|
137
|
+
try {
|
|
138
|
+
const ipRes = await fetch(`${IP_API_BASE_URL}/json/`);
|
|
139
|
+
if (ipRes.ok) {
|
|
140
|
+
const ipData = await ipRes.json();
|
|
141
|
+
ipAddress = ipData.ip || "";
|
|
142
|
+
country = ipData.country_name || ipData.country || "";
|
|
143
|
+
if (ipData.timezone) timezone = ipData.timezone;
|
|
144
|
+
}
|
|
145
|
+
} catch (e) {
|
|
146
|
+
}
|
|
147
|
+
finalDetails = {
|
|
148
|
+
...finalDetails,
|
|
149
|
+
ip_address: ipAddress,
|
|
150
|
+
country,
|
|
151
|
+
browser_os: browserOs,
|
|
152
|
+
timezone
|
|
153
|
+
};
|
|
154
|
+
}
|
|
89
155
|
const response = await this.makeBackendRequest(
|
|
90
156
|
"/installation-data",
|
|
91
157
|
{
|
|
92
158
|
method: "POST",
|
|
93
159
|
body: JSON.stringify({
|
|
94
160
|
platform: "strapi",
|
|
95
|
-
details:
|
|
96
|
-
version: pluginVersion,
|
|
97
|
-
site_url: siteUrl,
|
|
98
|
-
strapi_version: strapiVersion
|
|
99
|
-
}
|
|
161
|
+
details: finalDetails
|
|
100
162
|
})
|
|
101
163
|
},
|
|
102
164
|
true
|
|
103
165
|
);
|
|
104
|
-
if (response?.status === "success") {
|
|
166
|
+
if (response?.status === "success" && !settings2?.installationTracked) {
|
|
105
167
|
await this.settingsStore.set({
|
|
106
168
|
value: {
|
|
107
|
-
...settings2,
|
|
169
|
+
...settings2 || {},
|
|
170
|
+
installId,
|
|
108
171
|
installationTracked: true
|
|
109
172
|
}
|
|
110
173
|
});
|
|
@@ -114,24 +177,6 @@ const service = ({ strapi: strapi2 }) => ({
|
|
|
114
177
|
}
|
|
115
178
|
}
|
|
116
179
|
});
|
|
117
|
-
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
118
|
-
await service({ strapi: strapi2 }).trackInstallation();
|
|
119
|
-
};
|
|
120
|
-
const destroy = ({ strapi: strapi2 }) => {
|
|
121
|
-
};
|
|
122
|
-
const register = ({ strapi: strapi2 }) => {
|
|
123
|
-
};
|
|
124
|
-
const config = {
|
|
125
|
-
default: {},
|
|
126
|
-
validator() {
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
const contentTypes = {};
|
|
130
|
-
const controller = ({ strapi: strapi2 }) => ({
|
|
131
|
-
index(ctx) {
|
|
132
|
-
ctx.body = strapi2.plugin("upsnap").service("service").getWelcomeMessage();
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
180
|
const settings = ({ strapi: strapi2 }) => ({
|
|
136
181
|
async get(ctx) {
|
|
137
182
|
const settings2 = await service({ strapi: strapi2 }).settingsStore.get();
|
|
@@ -177,6 +222,37 @@ const settings = ({ strapi: strapi2 }) => ({
|
|
|
177
222
|
async getPrimaryMonitorId(ctx) {
|
|
178
223
|
const settings2 = await service({ strapi: strapi2 }).settingsStore.get();
|
|
179
224
|
ctx.body = { primaryMonitorId: settings2?.primaryMonitorId };
|
|
225
|
+
},
|
|
226
|
+
async trackUserData(ctx) {
|
|
227
|
+
const { browser, os, language, screen, client_timezone } = ctx.request.body || {};
|
|
228
|
+
const settings2 = await service({ strapi: strapi2 }).settingsStore.get();
|
|
229
|
+
if (settings2?.installationTracked) {
|
|
230
|
+
ctx.body = { ok: false, error: "Installation already tracked" };
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const ip = ctx.ip;
|
|
234
|
+
let country = "";
|
|
235
|
+
let ipAddress = ip;
|
|
236
|
+
try {
|
|
237
|
+
if (ip && ip !== "127.0.0.1" && ip !== "::1") {
|
|
238
|
+
const ipRes = await fetch(`${IP_API_BASE_URL}/${ip}/json/`);
|
|
239
|
+
if (ipRes.ok) {
|
|
240
|
+
const ipData = await ipRes.json();
|
|
241
|
+
country = ipData.country_name || ipData.country || "";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} catch (e) {
|
|
245
|
+
}
|
|
246
|
+
const userPayload = {
|
|
247
|
+
ip_address: ipAddress,
|
|
248
|
+
country,
|
|
249
|
+
browser_os: `${browser || ""} / ${os || ""}`,
|
|
250
|
+
timezone: client_timezone || "",
|
|
251
|
+
language: language || "",
|
|
252
|
+
screen: screen || ""
|
|
253
|
+
};
|
|
254
|
+
await service({ strapi: strapi2 }).trackInstallation(userPayload);
|
|
255
|
+
ctx.body = { ok: true };
|
|
180
256
|
}
|
|
181
257
|
});
|
|
182
258
|
function getMixedContentMessage(meta) {
|
|
@@ -1178,6 +1254,15 @@ const routes = {
|
|
|
1178
1254
|
auth: false
|
|
1179
1255
|
}
|
|
1180
1256
|
},
|
|
1257
|
+
{
|
|
1258
|
+
method: "POST",
|
|
1259
|
+
path: "/track-user-data",
|
|
1260
|
+
handler: "settings.trackUserData",
|
|
1261
|
+
config: {
|
|
1262
|
+
policies: [],
|
|
1263
|
+
auth: false
|
|
1264
|
+
}
|
|
1265
|
+
},
|
|
1181
1266
|
{
|
|
1182
1267
|
method: "GET",
|
|
1183
1268
|
path: "/monitor/:id",
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
3
|
+
};
|
|
4
|
+
const destroy = ({ strapi: strapi2 }) => {
|
|
5
|
+
};
|
|
6
|
+
const register = ({ strapi: strapi2 }) => {
|
|
7
|
+
};
|
|
8
|
+
const config = {
|
|
9
|
+
default: {},
|
|
10
|
+
validator() {
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const contentTypes = {};
|
|
14
|
+
const controller = ({ strapi: strapi2 }) => ({
|
|
15
|
+
index(ctx) {
|
|
16
|
+
ctx.body = strapi2.plugin("upsnap").service("service").getWelcomeMessage();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
1
19
|
const BACKEND_URL = "https://api.upsnap.ai/v1";
|
|
20
|
+
const IP_API_BASE_URL = "https://ipapi.co";
|
|
2
21
|
const LIGHTHOUSE_CHECKS = ["performance", "accessibility", "bestPractices", "seo", "pwa"];
|
|
3
|
-
const version = "1.0.
|
|
22
|
+
const version = "1.0.14";
|
|
4
23
|
const repository = { "type": "git", "url": "https://github.com/Appfoster/upsnap-strapi" };
|
|
5
24
|
const keywords = [];
|
|
6
25
|
const type = "commonjs";
|
|
@@ -75,7 +94,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
|
75
94
|
headers: response.headers
|
|
76
95
|
};
|
|
77
96
|
},
|
|
78
|
-
async trackInstallation() {
|
|
97
|
+
async trackInstallation(userPayload) {
|
|
79
98
|
try {
|
|
80
99
|
const settings2 = await this.settingsStore.get();
|
|
81
100
|
if (settings2?.installationTracked) {
|
|
@@ -84,25 +103,67 @@ const service = ({ strapi: strapi2 }) => ({
|
|
|
84
103
|
const pluginVersion = packageJson.version;
|
|
85
104
|
const strapiVersion = strapi2.config.get("info.strapi");
|
|
86
105
|
const siteUrl = strapi2.config.get("server.url") || `http://${strapi2.config.get("server.host") || "localhost"}:${strapi2.config.get("server.port") || 1337}`;
|
|
106
|
+
const users = await strapi2.db.query("admin::user").findMany({
|
|
107
|
+
orderBy: { createdAt: "ASC" },
|
|
108
|
+
limit: 1
|
|
109
|
+
});
|
|
110
|
+
const firstUser = users?.[0];
|
|
111
|
+
const email = firstUser?.email || "";
|
|
112
|
+
const name2 = `${firstUser?.firstname || ""} ${firstUser?.lastname || ""}`.trim();
|
|
113
|
+
const phoneNumber = firstUser?.phoneNumber || firstUser?.phone || "";
|
|
114
|
+
const company = firstUser?.company || "";
|
|
115
|
+
const installId = settings2?.installId || crypto.randomUUID();
|
|
116
|
+
let finalDetails = {
|
|
117
|
+
version: pluginVersion,
|
|
118
|
+
site_url: siteUrl,
|
|
119
|
+
strapi_version: strapiVersion,
|
|
120
|
+
install_id: installId,
|
|
121
|
+
email,
|
|
122
|
+
name: name2,
|
|
123
|
+
phone_number: phoneNumber,
|
|
124
|
+
company
|
|
125
|
+
};
|
|
126
|
+
if (userPayload) {
|
|
127
|
+
finalDetails = { ...finalDetails, ...userPayload };
|
|
128
|
+
} else {
|
|
129
|
+
let ipAddress = "";
|
|
130
|
+
let country = "";
|
|
131
|
+
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
|
|
132
|
+
let browserOs = `Node.js ${process.version} / ${process.platform}`;
|
|
133
|
+
try {
|
|
134
|
+
const ipRes = await fetch(`${IP_API_BASE_URL}/json/`);
|
|
135
|
+
if (ipRes.ok) {
|
|
136
|
+
const ipData = await ipRes.json();
|
|
137
|
+
ipAddress = ipData.ip || "";
|
|
138
|
+
country = ipData.country_name || ipData.country || "";
|
|
139
|
+
if (ipData.timezone) timezone = ipData.timezone;
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
}
|
|
143
|
+
finalDetails = {
|
|
144
|
+
...finalDetails,
|
|
145
|
+
ip_address: ipAddress,
|
|
146
|
+
country,
|
|
147
|
+
browser_os: browserOs,
|
|
148
|
+
timezone
|
|
149
|
+
};
|
|
150
|
+
}
|
|
87
151
|
const response = await this.makeBackendRequest(
|
|
88
152
|
"/installation-data",
|
|
89
153
|
{
|
|
90
154
|
method: "POST",
|
|
91
155
|
body: JSON.stringify({
|
|
92
156
|
platform: "strapi",
|
|
93
|
-
details:
|
|
94
|
-
version: pluginVersion,
|
|
95
|
-
site_url: siteUrl,
|
|
96
|
-
strapi_version: strapiVersion
|
|
97
|
-
}
|
|
157
|
+
details: finalDetails
|
|
98
158
|
})
|
|
99
159
|
},
|
|
100
160
|
true
|
|
101
161
|
);
|
|
102
|
-
if (response?.status === "success") {
|
|
162
|
+
if (response?.status === "success" && !settings2?.installationTracked) {
|
|
103
163
|
await this.settingsStore.set({
|
|
104
164
|
value: {
|
|
105
|
-
...settings2,
|
|
165
|
+
...settings2 || {},
|
|
166
|
+
installId,
|
|
106
167
|
installationTracked: true
|
|
107
168
|
}
|
|
108
169
|
});
|
|
@@ -112,24 +173,6 @@ const service = ({ strapi: strapi2 }) => ({
|
|
|
112
173
|
}
|
|
113
174
|
}
|
|
114
175
|
});
|
|
115
|
-
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
116
|
-
await service({ strapi: strapi2 }).trackInstallation();
|
|
117
|
-
};
|
|
118
|
-
const destroy = ({ strapi: strapi2 }) => {
|
|
119
|
-
};
|
|
120
|
-
const register = ({ strapi: strapi2 }) => {
|
|
121
|
-
};
|
|
122
|
-
const config = {
|
|
123
|
-
default: {},
|
|
124
|
-
validator() {
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const contentTypes = {};
|
|
128
|
-
const controller = ({ strapi: strapi2 }) => ({
|
|
129
|
-
index(ctx) {
|
|
130
|
-
ctx.body = strapi2.plugin("upsnap").service("service").getWelcomeMessage();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
176
|
const settings = ({ strapi: strapi2 }) => ({
|
|
134
177
|
async get(ctx) {
|
|
135
178
|
const settings2 = await service({ strapi: strapi2 }).settingsStore.get();
|
|
@@ -175,6 +218,37 @@ const settings = ({ strapi: strapi2 }) => ({
|
|
|
175
218
|
async getPrimaryMonitorId(ctx) {
|
|
176
219
|
const settings2 = await service({ strapi: strapi2 }).settingsStore.get();
|
|
177
220
|
ctx.body = { primaryMonitorId: settings2?.primaryMonitorId };
|
|
221
|
+
},
|
|
222
|
+
async trackUserData(ctx) {
|
|
223
|
+
const { browser, os, language, screen, client_timezone } = ctx.request.body || {};
|
|
224
|
+
const settings2 = await service({ strapi: strapi2 }).settingsStore.get();
|
|
225
|
+
if (settings2?.installationTracked) {
|
|
226
|
+
ctx.body = { ok: false, error: "Installation already tracked" };
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const ip = ctx.ip;
|
|
230
|
+
let country = "";
|
|
231
|
+
let ipAddress = ip;
|
|
232
|
+
try {
|
|
233
|
+
if (ip && ip !== "127.0.0.1" && ip !== "::1") {
|
|
234
|
+
const ipRes = await fetch(`${IP_API_BASE_URL}/${ip}/json/`);
|
|
235
|
+
if (ipRes.ok) {
|
|
236
|
+
const ipData = await ipRes.json();
|
|
237
|
+
country = ipData.country_name || ipData.country || "";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} catch (e) {
|
|
241
|
+
}
|
|
242
|
+
const userPayload = {
|
|
243
|
+
ip_address: ipAddress,
|
|
244
|
+
country,
|
|
245
|
+
browser_os: `${browser || ""} / ${os || ""}`,
|
|
246
|
+
timezone: client_timezone || "",
|
|
247
|
+
language: language || "",
|
|
248
|
+
screen: screen || ""
|
|
249
|
+
};
|
|
250
|
+
await service({ strapi: strapi2 }).trackInstallation(userPayload);
|
|
251
|
+
ctx.body = { ok: true };
|
|
178
252
|
}
|
|
179
253
|
});
|
|
180
254
|
function getMixedContentMessage(meta) {
|
|
@@ -1176,6 +1250,15 @@ const routes = {
|
|
|
1176
1250
|
auth: false
|
|
1177
1251
|
}
|
|
1178
1252
|
},
|
|
1253
|
+
{
|
|
1254
|
+
method: "POST",
|
|
1255
|
+
path: "/track-user-data",
|
|
1256
|
+
handler: "settings.trackUserData",
|
|
1257
|
+
config: {
|
|
1258
|
+
policies: [],
|
|
1259
|
+
auth: false
|
|
1260
|
+
}
|
|
1261
|
+
},
|
|
1179
1262
|
{
|
|
1180
1263
|
method: "GET",
|
|
1181
1264
|
path: "/monitor/:id",
|
|
@@ -25,6 +25,7 @@ declare const _default: {
|
|
|
25
25
|
set(ctx: any): Promise<void>;
|
|
26
26
|
setPrimaryMonitorId(ctx: any): Promise<void>;
|
|
27
27
|
getPrimaryMonitorId(ctx: any): Promise<void>;
|
|
28
|
+
trackUserData(ctx: any): Promise<void>;
|
|
28
29
|
};
|
|
29
30
|
monitor: ({ strapi }: {
|
|
30
31
|
strapi: import('@strapi/types/dist/core').Strapi;
|
|
@@ -146,7 +147,7 @@ declare const _default: {
|
|
|
146
147
|
};
|
|
147
148
|
getToken(): Promise<string>;
|
|
148
149
|
makeBackendRequest(endpoint: string, options: RequestInit, forValidation?: boolean, sessionToken?: string): Promise<unknown>;
|
|
149
|
-
trackInstallation(): Promise<void>;
|
|
150
|
+
trackInstallation(userPayload?: any): Promise<void>;
|
|
150
151
|
};
|
|
151
152
|
userDetailsService: ({ strapi }: {
|
|
152
153
|
strapi: import('@strapi/types/dist/core').Strapi;
|
package/package.json
CHANGED