trackfox-electron 1.0.2 → 1.0.5
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/dist/index.cjs +47 -23
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -23
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,10 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
|
+
// src/tracker.ts
|
|
38
|
+
var import_https = __toESM(require("https"), 1);
|
|
39
|
+
var import_http = __toESM(require("http"), 1);
|
|
40
|
+
|
|
37
41
|
// src/detection.ts
|
|
38
42
|
var import_os = __toESM(require("os"), 1);
|
|
39
43
|
function getElectronInfo(app, screen) {
|
|
@@ -155,6 +159,7 @@ var TrackFoxTracker = class {
|
|
|
155
159
|
this.options = {
|
|
156
160
|
apiUrl: "https://trackfox.app",
|
|
157
161
|
debug: false,
|
|
162
|
+
trackInDev: false,
|
|
158
163
|
...opts
|
|
159
164
|
};
|
|
160
165
|
this.userDataPath = app.getPath("userData");
|
|
@@ -183,6 +188,10 @@ var TrackFoxTracker = class {
|
|
|
183
188
|
if (this.options?.debug) console.warn("[TrackFox] SDK not initialized \u2014 call TrackFox.init() first");
|
|
184
189
|
return;
|
|
185
190
|
}
|
|
191
|
+
if (!this.electronInfo.isPackaged && !this.options.trackInDev) {
|
|
192
|
+
if (this.options.debug) console.log("[TrackFox] skipping event in dev mode (app.isPackaged=false). Set trackInDev:true to override.");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
186
195
|
refreshSession(this.userDataPath, this.sessionId);
|
|
187
196
|
const payload = {
|
|
188
197
|
type,
|
|
@@ -202,30 +211,45 @@ var TrackFoxTracker = class {
|
|
|
202
211
|
if (this.options.debug) console.log("[TrackFox]", payload);
|
|
203
212
|
this.queue.enqueue(payload);
|
|
204
213
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
214
|
+
send(payload) {
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
const body = JSON.stringify(payload);
|
|
217
|
+
const target = new URL(`${this.options.apiUrl}/api/events`);
|
|
218
|
+
const isHttps = target.protocol === "https:";
|
|
219
|
+
const port = target.port ? Number(target.port) : isHttps ? 443 : 80;
|
|
220
|
+
const req = (isHttps ? import_https.default : import_http.default).request(
|
|
221
|
+
{
|
|
222
|
+
hostname: target.hostname,
|
|
223
|
+
port,
|
|
224
|
+
path: target.pathname,
|
|
225
|
+
method: "POST",
|
|
226
|
+
headers: {
|
|
227
|
+
"Content-Type": "application/json",
|
|
228
|
+
"Content-Length": Buffer.byteLength(body),
|
|
229
|
+
"accept": "application/json",
|
|
230
|
+
"accept-language": "en-US,en;q=0.9"
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
(res) => {
|
|
234
|
+
let raw = "";
|
|
235
|
+
res.on("data", (chunk) => {
|
|
236
|
+
raw += chunk;
|
|
237
|
+
});
|
|
238
|
+
res.on("end", () => {
|
|
239
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
240
|
+
if (this.options?.debug) console.log("[TrackFox] sent:", payload.type, payload.href);
|
|
241
|
+
resolve();
|
|
242
|
+
} else {
|
|
243
|
+
reject(new Error(`TrackFox: HTTP ${res.statusCode} \u2014 ${raw}`));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
req.setTimeout(1e4, () => req.destroy(new Error("TrackFox: request timeout")));
|
|
249
|
+
req.on("error", reject);
|
|
250
|
+
req.write(body);
|
|
251
|
+
req.end();
|
|
223
252
|
});
|
|
224
|
-
if (!response.ok) {
|
|
225
|
-
const body = await response.text().catch(() => "");
|
|
226
|
-
throw new Error(`TrackFox: HTTP ${response.status}${body ? ` \u2014 ${body}` : ""}`);
|
|
227
|
-
}
|
|
228
|
-
if (this.options?.debug) console.log("[TrackFox] event sent:", payload.type, payload.href);
|
|
229
253
|
}
|
|
230
254
|
};
|
|
231
255
|
var TrackFox = new TrackFoxTracker();
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// src/tracker.ts
|
|
2
|
+
import https from "https";
|
|
3
|
+
import http from "http";
|
|
4
|
+
|
|
1
5
|
// src/detection.ts
|
|
2
6
|
import os from "os";
|
|
3
7
|
function getElectronInfo(app, screen) {
|
|
@@ -119,6 +123,7 @@ var TrackFoxTracker = class {
|
|
|
119
123
|
this.options = {
|
|
120
124
|
apiUrl: "https://trackfox.app",
|
|
121
125
|
debug: false,
|
|
126
|
+
trackInDev: false,
|
|
122
127
|
...opts
|
|
123
128
|
};
|
|
124
129
|
this.userDataPath = app.getPath("userData");
|
|
@@ -147,6 +152,10 @@ var TrackFoxTracker = class {
|
|
|
147
152
|
if (this.options?.debug) console.warn("[TrackFox] SDK not initialized \u2014 call TrackFox.init() first");
|
|
148
153
|
return;
|
|
149
154
|
}
|
|
155
|
+
if (!this.electronInfo.isPackaged && !this.options.trackInDev) {
|
|
156
|
+
if (this.options.debug) console.log("[TrackFox] skipping event in dev mode (app.isPackaged=false). Set trackInDev:true to override.");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
150
159
|
refreshSession(this.userDataPath, this.sessionId);
|
|
151
160
|
const payload = {
|
|
152
161
|
type,
|
|
@@ -166,30 +175,45 @@ var TrackFoxTracker = class {
|
|
|
166
175
|
if (this.options.debug) console.log("[TrackFox]", payload);
|
|
167
176
|
this.queue.enqueue(payload);
|
|
168
177
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
send(payload) {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
const body = JSON.stringify(payload);
|
|
181
|
+
const target = new URL(`${this.options.apiUrl}/api/events`);
|
|
182
|
+
const isHttps = target.protocol === "https:";
|
|
183
|
+
const port = target.port ? Number(target.port) : isHttps ? 443 : 80;
|
|
184
|
+
const req = (isHttps ? https : http).request(
|
|
185
|
+
{
|
|
186
|
+
hostname: target.hostname,
|
|
187
|
+
port,
|
|
188
|
+
path: target.pathname,
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers: {
|
|
191
|
+
"Content-Type": "application/json",
|
|
192
|
+
"Content-Length": Buffer.byteLength(body),
|
|
193
|
+
"accept": "application/json",
|
|
194
|
+
"accept-language": "en-US,en;q=0.9"
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
(res) => {
|
|
198
|
+
let raw = "";
|
|
199
|
+
res.on("data", (chunk) => {
|
|
200
|
+
raw += chunk;
|
|
201
|
+
});
|
|
202
|
+
res.on("end", () => {
|
|
203
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
204
|
+
if (this.options?.debug) console.log("[TrackFox] sent:", payload.type, payload.href);
|
|
205
|
+
resolve();
|
|
206
|
+
} else {
|
|
207
|
+
reject(new Error(`TrackFox: HTTP ${res.statusCode} \u2014 ${raw}`));
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
req.setTimeout(1e4, () => req.destroy(new Error("TrackFox: request timeout")));
|
|
213
|
+
req.on("error", reject);
|
|
214
|
+
req.write(body);
|
|
215
|
+
req.end();
|
|
187
216
|
});
|
|
188
|
-
if (!response.ok) {
|
|
189
|
-
const body = await response.text().catch(() => "");
|
|
190
|
-
throw new Error(`TrackFox: HTTP ${response.status}${body ? ` \u2014 ${body}` : ""}`);
|
|
191
|
-
}
|
|
192
|
-
if (this.options?.debug) console.log("[TrackFox] event sent:", payload.type, payload.href);
|
|
193
217
|
}
|
|
194
218
|
};
|
|
195
219
|
var TrackFox = new TrackFoxTracker();
|