trackfox-electron 1.0.1 → 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 +51 -14
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +51 -14
- 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) {
|
|
@@ -119,7 +123,8 @@ var EventQueue = class {
|
|
|
119
123
|
if (this.online) {
|
|
120
124
|
try {
|
|
121
125
|
await this.flush(payload);
|
|
122
|
-
} catch {
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.error("[TrackFox] send failed, queuing for retry:", err);
|
|
123
128
|
this.queue.push(payload);
|
|
124
129
|
}
|
|
125
130
|
} else {
|
|
@@ -131,7 +136,8 @@ var EventQueue = class {
|
|
|
131
136
|
for (const payload of pending) {
|
|
132
137
|
try {
|
|
133
138
|
await this.flush(payload);
|
|
134
|
-
} catch {
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.error("[TrackFox] retry failed:", err);
|
|
135
141
|
this.queue.unshift(payload);
|
|
136
142
|
break;
|
|
137
143
|
}
|
|
@@ -153,6 +159,7 @@ var TrackFoxTracker = class {
|
|
|
153
159
|
this.options = {
|
|
154
160
|
apiUrl: "https://trackfox.app",
|
|
155
161
|
debug: false,
|
|
162
|
+
trackInDev: false,
|
|
156
163
|
...opts
|
|
157
164
|
};
|
|
158
165
|
this.userDataPath = app.getPath("userData");
|
|
@@ -181,6 +188,10 @@ var TrackFoxTracker = class {
|
|
|
181
188
|
if (this.options?.debug) console.warn("[TrackFox] SDK not initialized \u2014 call TrackFox.init() first");
|
|
182
189
|
return;
|
|
183
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
|
+
}
|
|
184
195
|
refreshSession(this.userDataPath, this.sessionId);
|
|
185
196
|
const payload = {
|
|
186
197
|
type,
|
|
@@ -200,19 +211,45 @@ var TrackFoxTracker = class {
|
|
|
200
211
|
if (this.options.debug) console.log("[TrackFox]", payload);
|
|
201
212
|
this.queue.enqueue(payload);
|
|
202
213
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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();
|
|
214
252
|
});
|
|
215
|
-
if (!response.ok) throw new Error(`TrackFox: ${response.status}`);
|
|
216
253
|
}
|
|
217
254
|
};
|
|
218
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) {
|
|
@@ -83,7 +87,8 @@ var EventQueue = class {
|
|
|
83
87
|
if (this.online) {
|
|
84
88
|
try {
|
|
85
89
|
await this.flush(payload);
|
|
86
|
-
} catch {
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error("[TrackFox] send failed, queuing for retry:", err);
|
|
87
92
|
this.queue.push(payload);
|
|
88
93
|
}
|
|
89
94
|
} else {
|
|
@@ -95,7 +100,8 @@ var EventQueue = class {
|
|
|
95
100
|
for (const payload of pending) {
|
|
96
101
|
try {
|
|
97
102
|
await this.flush(payload);
|
|
98
|
-
} catch {
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.error("[TrackFox] retry failed:", err);
|
|
99
105
|
this.queue.unshift(payload);
|
|
100
106
|
break;
|
|
101
107
|
}
|
|
@@ -117,6 +123,7 @@ var TrackFoxTracker = class {
|
|
|
117
123
|
this.options = {
|
|
118
124
|
apiUrl: "https://trackfox.app",
|
|
119
125
|
debug: false,
|
|
126
|
+
trackInDev: false,
|
|
120
127
|
...opts
|
|
121
128
|
};
|
|
122
129
|
this.userDataPath = app.getPath("userData");
|
|
@@ -145,6 +152,10 @@ var TrackFoxTracker = class {
|
|
|
145
152
|
if (this.options?.debug) console.warn("[TrackFox] SDK not initialized \u2014 call TrackFox.init() first");
|
|
146
153
|
return;
|
|
147
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
|
+
}
|
|
148
159
|
refreshSession(this.userDataPath, this.sessionId);
|
|
149
160
|
const payload = {
|
|
150
161
|
type,
|
|
@@ -164,19 +175,45 @@ var TrackFoxTracker = class {
|
|
|
164
175
|
if (this.options.debug) console.log("[TrackFox]", payload);
|
|
165
176
|
this.queue.enqueue(payload);
|
|
166
177
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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();
|
|
178
216
|
});
|
|
179
|
-
if (!response.ok) throw new Error(`TrackFox: ${response.status}`);
|
|
180
217
|
}
|
|
181
218
|
};
|
|
182
219
|
var TrackFox = new TrackFoxTracker();
|