@farm.js/cli 0.1.0-beta.7 → 0.1.0-beta.70

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.
@@ -0,0 +1,28 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ Object.defineProperty(exports, "__toESM", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return __toESM;
27
+ }
28
+ });
@@ -0,0 +1,513 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.js");
2
+ let node_fs_promises = require("node:fs/promises");
3
+ let node_path = require("node:path");
4
+ node_path = require_rolldown_runtime.__toESM(node_path);
5
+ let node_crypto = require("node:crypto");
6
+ let node_http = require("node:http");
7
+ let node_https = require("node:https");
8
+ let node_os = require("node:os");
9
+ node_os = require_rolldown_runtime.__toESM(node_os);
10
+ //#region src/telemetry-contract.ts
11
+ const FARM_TELEMETRY_COMMANDS = [
12
+ "dev",
13
+ "build",
14
+ "start",
15
+ "auth:migrate",
16
+ "upgrade",
17
+ "generate",
18
+ "doctor",
19
+ "explain",
20
+ "preview",
21
+ "migrate",
22
+ "cron:list",
23
+ "cron:run",
24
+ "add:integration",
25
+ "deploy"
26
+ ];
27
+ const FARM_CREATE_APP_TELEMETRY_COMMANDS = ["create", "list-templates"];
28
+ const FARM_TELEMETRY_TEMPLATES = [
29
+ "basic",
30
+ "react-compiler",
31
+ "auth",
32
+ "better-auth",
33
+ "ai",
34
+ "auth0",
35
+ "authjs",
36
+ "autumn",
37
+ "clerk",
38
+ "jobs-inngest",
39
+ "jobs-trigger",
40
+ "polar",
41
+ "resend",
42
+ "stripe",
43
+ "supabase",
44
+ "unkey",
45
+ "workos"
46
+ ];
47
+ const FARM_TELEMETRY_RENDERERS = [
48
+ "react",
49
+ "preact",
50
+ "solid",
51
+ "vue",
52
+ "svelte"
53
+ ];
54
+ const FARM_TELEMETRY_PACKAGE_MANAGERS = [
55
+ "npm",
56
+ "pnpm",
57
+ "yarn",
58
+ "bun"
59
+ ];
60
+ const FARM_TELEMETRY_DEPLOY_TARGETS = [
61
+ "vercel",
62
+ "cloudflare",
63
+ "netlify",
64
+ "node",
65
+ "custom"
66
+ ];
67
+ //#endregion
68
+ //#region src/telemetry.ts
69
+ const TELEMETRY_SCHEMA_VERSION = 1;
70
+ const DEFAULT_TELEMETRY_ENDPOINT = "https://farmjs.dev/api/telemetry/v1/events";
71
+ const TELEMETRY_NOTICE_URL = "https://farmjs.dev/docs/telemetry";
72
+ const REQUEST_TIMEOUT_MS = 3e3;
73
+ const RETRY_DELAYS_MS = [250, 750];
74
+ const pendingDeliveries = /* @__PURE__ */ new Set();
75
+ const retryTimers = /* @__PURE__ */ new Set();
76
+ let telemetryFlushWaiters = 0;
77
+ function defaultConfig() {
78
+ return {
79
+ version: TELEMETRY_SCHEMA_VERSION,
80
+ enabled: true,
81
+ noticeShown: false
82
+ };
83
+ }
84
+ function configDirectory() {
85
+ if (process.env.FARM_TELEMETRY_CONFIG_DIR) return node_path.default.resolve(process.env.FARM_TELEMETRY_CONFIG_DIR);
86
+ if (process.platform === "win32") return node_path.default.join(process.env.APPDATA || node_path.default.join(node_os.default.homedir(), "AppData", "Roaming"), "farmjs");
87
+ if (process.platform === "darwin") return node_path.default.join(node_os.default.homedir(), "Library", "Application Support", "farmjs");
88
+ return node_path.default.join(process.env.XDG_CONFIG_HOME || node_path.default.join(node_os.default.homedir(), ".config"), "farmjs");
89
+ }
90
+ function getFarmTelemetryConfigFile() {
91
+ return node_path.default.join(configDirectory(), "telemetry.json");
92
+ }
93
+ async function readConfig() {
94
+ try {
95
+ const parsed = JSON.parse(await (0, node_fs_promises.readFile)(getFarmTelemetryConfigFile(), "utf8"));
96
+ if (parsed.version !== TELEMETRY_SCHEMA_VERSION) return {
97
+ config: defaultConfig(),
98
+ stored: false
99
+ };
100
+ return {
101
+ config: {
102
+ version: TELEMETRY_SCHEMA_VERSION,
103
+ enabled: parsed.enabled === true,
104
+ noticeShown: parsed.noticeShown === true,
105
+ anonymousId: isUuid(parsed.anonymousId) ? parsed.anonymousId : void 0
106
+ },
107
+ stored: true
108
+ };
109
+ } catch {
110
+ return {
111
+ config: defaultConfig(),
112
+ stored: false
113
+ };
114
+ }
115
+ }
116
+ async function writeConfig(config) {
117
+ const file = getFarmTelemetryConfigFile();
118
+ const directory = node_path.default.dirname(file);
119
+ const temporaryFile = `${file}.${process.pid}.${(0, node_crypto.randomUUID)()}.tmp`;
120
+ try {
121
+ await (0, node_fs_promises.mkdir)(directory, {
122
+ recursive: true,
123
+ mode: 448
124
+ });
125
+ await (0, node_fs_promises.writeFile)(temporaryFile, `${JSON.stringify(config, null, 2)}\n`, { mode: 384 });
126
+ await (0, node_fs_promises.rename)(temporaryFile, file);
127
+ await (0, node_fs_promises.chmod)(file, 384).catch(() => void 0);
128
+ } catch {
129
+ await (0, node_fs_promises.unlink)(temporaryFile).catch(() => void 0);
130
+ }
131
+ }
132
+ function isUuid(value) {
133
+ return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
134
+ }
135
+ function isTrue(value) {
136
+ return value !== void 0 && [
137
+ "1",
138
+ "true",
139
+ "yes",
140
+ "on"
141
+ ].includes(value.toLowerCase());
142
+ }
143
+ function isFalse(value) {
144
+ return value !== void 0 && [
145
+ "0",
146
+ "false",
147
+ "no",
148
+ "off"
149
+ ].includes(value.toLowerCase());
150
+ }
151
+ function environmentDecision() {
152
+ if (process.env.DO_NOT_TRACK !== void 0 && !isFalse(process.env.DO_NOT_TRACK)) return {
153
+ enabled: false,
154
+ reason: "DO_NOT_TRACK is set"
155
+ };
156
+ if (isTrue(process.env.FARM_TELEMETRY_DISABLED)) return {
157
+ enabled: false,
158
+ reason: "FARM_TELEMETRY_DISABLED is set"
159
+ };
160
+ if (isTrue(process.env.FARM_TELEMETRY)) return { enabled: true };
161
+ if (isFalse(process.env.FARM_TELEMETRY)) return {
162
+ enabled: false,
163
+ reason: "FARM_TELEMETRY disables collection"
164
+ };
165
+ return {};
166
+ }
167
+ function isContinuousIntegration() {
168
+ return isTrue(process.env.CI) || isTrue(process.env.GITHUB_ACTIONS) || isTrue(process.env.BUILDKITE) || isTrue(process.env.CIRCLECI);
169
+ }
170
+ function isInteractive() {
171
+ return process.stdin.isTTY === true && process.stdout.isTTY === true;
172
+ }
173
+ function getEndpoint() {
174
+ const candidate = process.env.FARM_TELEMETRY_ENDPOINT || DEFAULT_TELEMETRY_ENDPOINT;
175
+ try {
176
+ const url = new URL(candidate);
177
+ const isLocal = [
178
+ "localhost",
179
+ "127.0.0.1",
180
+ "::1"
181
+ ].includes(url.hostname);
182
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && isLocal)) return DEFAULT_TELEMETRY_ENDPOINT;
183
+ return url.toString();
184
+ } catch {
185
+ return DEFAULT_TELEMETRY_ENDPOINT;
186
+ }
187
+ }
188
+ async function resolveState() {
189
+ const { config, stored } = await readConfig();
190
+ const environment = environmentDecision();
191
+ const enabled = environment.enabled ?? config.enabled;
192
+ const source = environment.enabled !== void 0 ? "environment" : stored ? "configuration" : "default";
193
+ if (!enabled) return {
194
+ config,
195
+ enabled,
196
+ active: false,
197
+ source,
198
+ reason: environment.reason
199
+ };
200
+ if (environment.enabled === true) return {
201
+ config,
202
+ enabled,
203
+ active: true,
204
+ source
205
+ };
206
+ if (process.env.NODE_ENV === "test") return {
207
+ config,
208
+ enabled,
209
+ active: false,
210
+ source,
211
+ reason: "test environments are skipped"
212
+ };
213
+ if (isContinuousIntegration()) return {
214
+ config,
215
+ enabled,
216
+ active: false,
217
+ source,
218
+ reason: "CI environments are skipped"
219
+ };
220
+ if (!isInteractive()) return {
221
+ config,
222
+ enabled,
223
+ active: false,
224
+ source,
225
+ reason: "non-interactive commands are skipped"
226
+ };
227
+ return {
228
+ config,
229
+ enabled,
230
+ active: true,
231
+ source
232
+ };
233
+ }
234
+ async function getFarmTelemetryStatus() {
235
+ const state = await resolveState();
236
+ return {
237
+ enabled: state.enabled,
238
+ active: state.active,
239
+ source: state.source,
240
+ endpoint: getEndpoint(),
241
+ configFile: getFarmTelemetryConfigFile(),
242
+ anonymousId: state.config.anonymousId,
243
+ reason: state.reason
244
+ };
245
+ }
246
+ async function setFarmTelemetryEnabled(enabled) {
247
+ const { config: current } = await readConfig();
248
+ await writeConfig({
249
+ version: TELEMETRY_SCHEMA_VERSION,
250
+ enabled,
251
+ noticeShown: true,
252
+ anonymousId: enabled ? current.anonymousId || (0, node_crypto.randomUUID)() : void 0
253
+ });
254
+ return getFarmTelemetryStatus();
255
+ }
256
+ async function showFarmTelemetryNotice() {
257
+ if (!isInteractive() || isContinuousIntegration() || process.env.NODE_ENV === "test") return;
258
+ if (environmentDecision().enabled !== void 0) return;
259
+ const { config } = await readConfig();
260
+ if (config.noticeShown) return;
261
+ process.stderr.write(`Farm.js collects anonymous CLI telemetry by default. Run "farm telemetry disable" to opt out.\nLearn more: ${TELEMETRY_NOTICE_URL}\n`);
262
+ await writeConfig({
263
+ ...config,
264
+ noticeShown: true
265
+ });
266
+ }
267
+ function resolveFarmTelemetryCommand(value) {
268
+ return FARM_TELEMETRY_COMMANDS.includes(value) ? value : void 0;
269
+ }
270
+ function resolveFarmCreateAppTelemetryCommand(value) {
271
+ return FARM_CREATE_APP_TELEMETRY_COMMANDS.includes(value) ? value : void 0;
272
+ }
273
+ function trackFarmCommand(input) {
274
+ return schedule(async () => {
275
+ await showFarmTelemetryNotice();
276
+ const deployTarget = allowlisted(input.deployTarget, FARM_TELEMETRY_DEPLOY_TARGETS);
277
+ await track({
278
+ eventType: "command_invoked",
279
+ source: "cli",
280
+ packageName: "@farm.js/cli",
281
+ packageVersion: sanitizeVersion(input.packageVersion),
282
+ command: input.command,
283
+ ...deployTarget ? { deployTarget } : {}
284
+ });
285
+ });
286
+ }
287
+ function trackFarmCreateAppCommand(input) {
288
+ return schedule(async () => {
289
+ await showFarmTelemetryNotice();
290
+ const command = allowlisted(input.command, FARM_CREATE_APP_TELEMETRY_COMMANDS);
291
+ if (!command) return;
292
+ await track({
293
+ eventType: "command_invoked",
294
+ source: "create-app",
295
+ packageName: "@farm.js/create-app",
296
+ packageVersion: sanitizeVersion(input.packageVersion),
297
+ command
298
+ });
299
+ });
300
+ }
301
+ function trackFarmProjectCreated(input) {
302
+ return schedule(async () => {
303
+ const template = allowlisted(input.template, FARM_TELEMETRY_TEMPLATES);
304
+ const renderer = allowlisted(input.renderer, FARM_TELEMETRY_RENDERERS);
305
+ const packageManager = allowlisted(input.packageManager, FARM_TELEMETRY_PACKAGE_MANAGERS);
306
+ await track({
307
+ eventType: "project_created",
308
+ source: "create-app",
309
+ packageName: "@farm.js/create-app",
310
+ packageVersion: sanitizeVersion(input.packageVersion),
311
+ ...template ? { template } : {},
312
+ ...renderer ? { renderer } : {},
313
+ ...packageManager ? { packageManager } : {},
314
+ ...typeof input.typescript === "boolean" ? { typescript: input.typescript } : {},
315
+ ...typeof input.installedDependencies === "boolean" ? { installedDependencies: input.installedDependencies } : {}
316
+ });
317
+ });
318
+ }
319
+ function schedule(delivery) {
320
+ const pending = Promise.resolve().then(delivery).catch(() => {});
321
+ pendingDeliveries.add(pending);
322
+ pending.finally(() => pendingDeliveries.delete(pending));
323
+ return Promise.resolve();
324
+ }
325
+ /** Wait for background telemetry. Intended for tests and explicit process shutdown hooks. */
326
+ async function flushFarmTelemetry() {
327
+ telemetryFlushWaiters += 1;
328
+ for (const timer of retryTimers) timer.ref?.();
329
+ try {
330
+ while (pendingDeliveries.size > 0) await Promise.allSettled(pendingDeliveries);
331
+ } finally {
332
+ telemetryFlushWaiters -= 1;
333
+ if (telemetryFlushWaiters === 0) for (const timer of retryTimers) timer.unref?.();
334
+ }
335
+ }
336
+ async function track(event) {
337
+ try {
338
+ const state = await resolveState();
339
+ if (!state.active) return;
340
+ const anonymousId = state.config.anonymousId || (0, node_crypto.randomUUID)();
341
+ if (!state.config.anonymousId) await writeConfig({
342
+ ...state.config,
343
+ anonymousId
344
+ });
345
+ await send({
346
+ schemaVersion: TELEMETRY_SCHEMA_VERSION,
347
+ eventId: (0, node_crypto.randomUUID)(),
348
+ anonymousId,
349
+ nodeMajor: Number.parseInt(process.versions.node.split(".")[0] || "0", 10),
350
+ platform: normalizePlatform(process.platform),
351
+ architecture: normalizeArchitecture(process.arch),
352
+ ...event
353
+ });
354
+ } catch {}
355
+ }
356
+ async function send(payload) {
357
+ for (let attempt = 0; attempt <= RETRY_DELAYS_MS.length; attempt += 1) {
358
+ const result = await sendOnce(payload);
359
+ if (result === "delivered" || result === "rejected") return;
360
+ const delay = RETRY_DELAYS_MS[attempt];
361
+ if (delay !== void 0) await wait(delay);
362
+ }
363
+ debug("delivery failed after retries");
364
+ }
365
+ async function sendOnce(payload) {
366
+ let endpoint;
367
+ try {
368
+ endpoint = new URL(getEndpoint());
369
+ } catch {
370
+ debug("invalid endpoint URL");
371
+ return "rejected";
372
+ }
373
+ const requestTransport = endpoint.protocol === "http:" ? node_http.request : node_https.request;
374
+ if (endpoint.protocol !== "http:" && endpoint.protocol !== "https:") {
375
+ debug(`unsupported endpoint protocol ${endpoint.protocol}`);
376
+ return "rejected";
377
+ }
378
+ const body = JSON.stringify(payload);
379
+ return new Promise((resolve) => {
380
+ let settled = false;
381
+ const finish = (result) => {
382
+ if (settled) return;
383
+ settled = true;
384
+ clearTimeout(timeout);
385
+ resolve(result);
386
+ };
387
+ const request = requestTransport(endpoint, {
388
+ method: "POST",
389
+ headers: {
390
+ "content-type": "application/json",
391
+ "content-length": Buffer.byteLength(body)
392
+ }
393
+ }, (response) => {
394
+ response.on("error", () => {});
395
+ response.resume();
396
+ const status = response.statusCode ?? 0;
397
+ if (status >= 200 && status < 300) return finish("delivered");
398
+ if (status === 408 || status === 425 || status === 429) {
399
+ debug(`temporary HTTP ${status}; retrying`);
400
+ return finish("retry");
401
+ }
402
+ if (status >= 500) {
403
+ debug(`server HTTP ${status}; retrying`);
404
+ return finish("retry");
405
+ }
406
+ debug(`event rejected with HTTP ${status}`);
407
+ return finish("rejected");
408
+ });
409
+ const timeout = setTimeout(() => {
410
+ request.destroy();
411
+ debug("network request timed out; retrying");
412
+ finish("retry");
413
+ }, REQUEST_TIMEOUT_MS);
414
+ timeout.unref?.();
415
+ request.once("socket", (socket) => socket.unref());
416
+ request.once("error", () => {
417
+ debug("network request failed; retrying");
418
+ finish("retry");
419
+ });
420
+ request.end(body);
421
+ });
422
+ }
423
+ function wait(delay) {
424
+ return new Promise((resolve) => {
425
+ const timeout = setTimeout(() => {
426
+ retryTimers.delete(timeout);
427
+ resolve();
428
+ }, delay);
429
+ retryTimers.add(timeout);
430
+ if (telemetryFlushWaiters === 0) timeout.unref?.();
431
+ });
432
+ }
433
+ function debug(message) {
434
+ if (!isTrue(process.env.FARM_TELEMETRY_DEBUG)) return;
435
+ process.stderr.write(`[farm.telemetry] ${message}\n`);
436
+ }
437
+ function sanitizeVersion(value) {
438
+ return /^[0-9A-Za-z.+_-]{1,64}$/.test(value) ? value : "unknown";
439
+ }
440
+ function allowlisted(value, values) {
441
+ return value && values.includes(value) ? value : void 0;
442
+ }
443
+ function normalizePlatform(value) {
444
+ if (value === "darwin" || value === "linux") return value;
445
+ if (value === "win32") return "windows";
446
+ return "other";
447
+ }
448
+ function normalizeArchitecture(value) {
449
+ return value === "arm64" || value === "x64" ? value : "other";
450
+ }
451
+ //#endregion
452
+ Object.defineProperty(exports, "flushFarmTelemetry", {
453
+ enumerable: true,
454
+ get: function() {
455
+ return flushFarmTelemetry;
456
+ }
457
+ });
458
+ Object.defineProperty(exports, "getFarmTelemetryConfigFile", {
459
+ enumerable: true,
460
+ get: function() {
461
+ return getFarmTelemetryConfigFile;
462
+ }
463
+ });
464
+ Object.defineProperty(exports, "getFarmTelemetryStatus", {
465
+ enumerable: true,
466
+ get: function() {
467
+ return getFarmTelemetryStatus;
468
+ }
469
+ });
470
+ Object.defineProperty(exports, "resolveFarmCreateAppTelemetryCommand", {
471
+ enumerable: true,
472
+ get: function() {
473
+ return resolveFarmCreateAppTelemetryCommand;
474
+ }
475
+ });
476
+ Object.defineProperty(exports, "resolveFarmTelemetryCommand", {
477
+ enumerable: true,
478
+ get: function() {
479
+ return resolveFarmTelemetryCommand;
480
+ }
481
+ });
482
+ Object.defineProperty(exports, "setFarmTelemetryEnabled", {
483
+ enumerable: true,
484
+ get: function() {
485
+ return setFarmTelemetryEnabled;
486
+ }
487
+ });
488
+ Object.defineProperty(exports, "showFarmTelemetryNotice", {
489
+ enumerable: true,
490
+ get: function() {
491
+ return showFarmTelemetryNotice;
492
+ }
493
+ });
494
+ Object.defineProperty(exports, "trackFarmCommand", {
495
+ enumerable: true,
496
+ get: function() {
497
+ return trackFarmCommand;
498
+ }
499
+ });
500
+ Object.defineProperty(exports, "trackFarmCreateAppCommand", {
501
+ enumerable: true,
502
+ get: function() {
503
+ return trackFarmCreateAppCommand;
504
+ }
505
+ });
506
+ Object.defineProperty(exports, "trackFarmProjectCreated", {
507
+ enumerable: true,
508
+ get: function() {
509
+ return trackFarmProjectCreated;
510
+ }
511
+ });
512
+
513
+ //# sourceMappingURL=telemetry-9Y6041mK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-9Y6041mK.js","names":["path","os","readFile","randomUUID","mkdir","writeFile","rename","chmod","unlink","httpRequest","httpsRequest"],"sources":["../src/telemetry-contract.ts","../src/telemetry.ts"],"sourcesContent":["export const FARM_TELEMETRY_COMMANDS = [\n \"dev\",\n \"build\",\n \"start\",\n \"auth:migrate\",\n \"upgrade\",\n \"generate\",\n \"doctor\",\n \"explain\",\n \"preview\",\n \"migrate\",\n \"cron:list\",\n \"cron:run\",\n \"add:integration\",\n \"deploy\",\n] as const;\n\nexport const FARM_CREATE_APP_TELEMETRY_COMMANDS = [\"create\", \"list-templates\"] as const;\n\nexport const FARM_TELEMETRY_TEMPLATES = [\n \"basic\",\n \"react-compiler\",\n \"auth\",\n \"better-auth\",\n \"ai\",\n \"auth0\",\n \"authjs\",\n \"autumn\",\n \"clerk\",\n \"jobs-inngest\",\n \"jobs-trigger\",\n \"polar\",\n \"resend\",\n \"stripe\",\n \"supabase\",\n \"unkey\",\n \"workos\",\n] as const;\n\nexport const FARM_TELEMETRY_RENDERERS = [\"react\", \"preact\", \"solid\", \"vue\", \"svelte\"] as const;\nexport const FARM_TELEMETRY_PACKAGE_MANAGERS = [\"npm\", \"pnpm\", \"yarn\", \"bun\"] as const;\nexport const FARM_TELEMETRY_DEPLOY_TARGETS = [\n \"vercel\",\n \"cloudflare\",\n \"netlify\",\n \"node\",\n \"custom\",\n] as const;\n","import { randomUUID } from \"node:crypto\";\nimport { chmod, mkdir, readFile, rename, unlink, writeFile } from \"node:fs/promises\";\nimport { request as httpRequest } from \"node:http\";\nimport { request as httpsRequest } from \"node:https\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport {\n FARM_CREATE_APP_TELEMETRY_COMMANDS,\n FARM_TELEMETRY_COMMANDS,\n FARM_TELEMETRY_DEPLOY_TARGETS,\n FARM_TELEMETRY_PACKAGE_MANAGERS,\n FARM_TELEMETRY_RENDERERS,\n FARM_TELEMETRY_TEMPLATES,\n} from \"./telemetry-contract\";\n\nconst TELEMETRY_SCHEMA_VERSION = 1 as const;\nconst DEFAULT_TELEMETRY_ENDPOINT = \"https://farmjs.dev/api/telemetry/v1/events\";\nconst TELEMETRY_NOTICE_URL = \"https://farmjs.dev/docs/telemetry\";\nconst REQUEST_TIMEOUT_MS = 3_000;\nconst RETRY_DELAYS_MS = [250, 750] as const;\n\nexport type FarmTelemetryCommand = (typeof FARM_TELEMETRY_COMMANDS)[number];\nexport type FarmCreateAppTelemetryCommand = (typeof FARM_CREATE_APP_TELEMETRY_COMMANDS)[number];\nexport type FarmTelemetryTemplate = (typeof FARM_TELEMETRY_TEMPLATES)[number];\nexport type FarmTelemetryRenderer = (typeof FARM_TELEMETRY_RENDERERS)[number];\nexport type FarmTelemetryPackageManager = (typeof FARM_TELEMETRY_PACKAGE_MANAGERS)[number];\nexport type FarmTelemetryDeployTarget = (typeof FARM_TELEMETRY_DEPLOY_TARGETS)[number];\n\ninterface FarmTelemetryConfig {\n version: 1;\n enabled: boolean;\n noticeShown: boolean;\n anonymousId?: string;\n}\n\ninterface FarmTelemetryConfigState {\n config: FarmTelemetryConfig;\n stored: boolean;\n}\n\ninterface FarmTelemetryEventBase {\n schemaVersion: typeof TELEMETRY_SCHEMA_VERSION;\n eventId: string;\n anonymousId: string;\n source: \"cli\" | \"create-app\";\n packageName: \"@farm.js/cli\" | \"@farm.js/create-app\";\n packageVersion: string;\n nodeMajor: number;\n platform: \"darwin\" | \"linux\" | \"windows\" | \"other\";\n architecture: \"arm64\" | \"x64\" | \"other\";\n}\n\nexport interface FarmCommandTelemetryInput {\n command: FarmTelemetryCommand;\n packageVersion: string;\n deployTarget?: string;\n}\n\nexport interface FarmCreateAppCommandTelemetryInput {\n command: FarmCreateAppTelemetryCommand;\n packageVersion: string;\n}\n\nexport interface FarmProjectCreatedTelemetryInput {\n packageVersion: string;\n template?: string;\n renderer?: string;\n packageManager?: string;\n typescript?: boolean;\n installedDependencies?: boolean;\n}\n\nexport interface FarmTelemetryStatus {\n enabled: boolean;\n active: boolean;\n source: \"configuration\" | \"environment\" | \"default\";\n endpoint: string;\n configFile: string;\n anonymousId?: string;\n reason?: string;\n}\n\ntype FarmTelemetryEvent =\n | (FarmTelemetryEventBase & {\n eventType: \"command_invoked\";\n source: \"cli\";\n packageName: \"@farm.js/cli\";\n command: FarmTelemetryCommand;\n deployTarget?: FarmTelemetryDeployTarget;\n })\n | (FarmTelemetryEventBase & {\n eventType: \"command_invoked\";\n source: \"create-app\";\n packageName: \"@farm.js/create-app\";\n command: FarmCreateAppTelemetryCommand;\n })\n | (FarmTelemetryEventBase & {\n eventType: \"project_created\";\n source: \"create-app\";\n packageName: \"@farm.js/create-app\";\n template?: FarmTelemetryTemplate;\n renderer?: FarmTelemetryRenderer;\n packageManager?: FarmTelemetryPackageManager;\n typescript?: boolean;\n installedDependencies?: boolean;\n });\n\ntype FarmTelemetryGeneratedFields = Pick<\n FarmTelemetryEventBase,\n \"schemaVersion\" | \"eventId\" | \"anonymousId\" | \"nodeMajor\" | \"platform\" | \"architecture\"\n>;\ntype FarmTelemetryEventInput<T = FarmTelemetryEvent> = T extends FarmTelemetryEvent\n ? Omit<T, keyof FarmTelemetryGeneratedFields>\n : never;\n\nconst pendingDeliveries = new Set<Promise<void>>();\nconst retryTimers = new Set<NodeJS.Timeout>();\nlet telemetryFlushWaiters = 0;\n\nfunction defaultConfig(): FarmTelemetryConfig {\n return {\n version: TELEMETRY_SCHEMA_VERSION,\n enabled: true,\n noticeShown: false,\n };\n}\n\nfunction configDirectory(): string {\n if (process.env.FARM_TELEMETRY_CONFIG_DIR) {\n return path.resolve(process.env.FARM_TELEMETRY_CONFIG_DIR);\n }\n if (process.platform === \"win32\") {\n return path.join(\n process.env.APPDATA || path.join(os.homedir(), \"AppData\", \"Roaming\"),\n \"farmjs\",\n );\n }\n if (process.platform === \"darwin\") {\n return path.join(os.homedir(), \"Library\", \"Application Support\", \"farmjs\");\n }\n return path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), \".config\"), \"farmjs\");\n}\n\nexport function getFarmTelemetryConfigFile(): string {\n return path.join(configDirectory(), \"telemetry.json\");\n}\n\nasync function readConfig(): Promise<FarmTelemetryConfigState> {\n try {\n const parsed = JSON.parse(\n await readFile(getFarmTelemetryConfigFile(), \"utf8\"),\n ) as Partial<FarmTelemetryConfig>;\n if (parsed.version !== TELEMETRY_SCHEMA_VERSION) {\n return { config: defaultConfig(), stored: false };\n }\n return {\n config: {\n version: TELEMETRY_SCHEMA_VERSION,\n enabled: parsed.enabled === true,\n noticeShown: parsed.noticeShown === true,\n anonymousId: isUuid(parsed.anonymousId) ? parsed.anonymousId : undefined,\n },\n stored: true,\n };\n } catch {\n return { config: defaultConfig(), stored: false };\n }\n}\n\nasync function writeConfig(config: FarmTelemetryConfig): Promise<void> {\n const file = getFarmTelemetryConfigFile();\n const directory = path.dirname(file);\n const temporaryFile = `${file}.${process.pid}.${randomUUID()}.tmp`;\n try {\n await mkdir(directory, { recursive: true, mode: 0o700 });\n await writeFile(temporaryFile, `${JSON.stringify(config, null, 2)}\\n`, { mode: 0o600 });\n await rename(temporaryFile, file);\n await chmod(file, 0o600).catch(() => undefined);\n } catch {\n await unlink(temporaryFile).catch(() => undefined);\n // Telemetry is best-effort and must never make a Farm command fail.\n }\n}\n\nfunction isUuid(value: unknown): value is string {\n return (\n typeof value === \"string\" &&\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)\n );\n}\n\nfunction isTrue(value: string | undefined): boolean {\n return value !== undefined && [\"1\", \"true\", \"yes\", \"on\"].includes(value.toLowerCase());\n}\n\nfunction isFalse(value: string | undefined): boolean {\n return value !== undefined && [\"0\", \"false\", \"no\", \"off\"].includes(value.toLowerCase());\n}\n\nfunction environmentDecision(): { enabled?: boolean; reason?: string } {\n if (process.env.DO_NOT_TRACK !== undefined && !isFalse(process.env.DO_NOT_TRACK)) {\n return { enabled: false, reason: \"DO_NOT_TRACK is set\" };\n }\n if (isTrue(process.env.FARM_TELEMETRY_DISABLED)) {\n return { enabled: false, reason: \"FARM_TELEMETRY_DISABLED is set\" };\n }\n if (isTrue(process.env.FARM_TELEMETRY)) return { enabled: true };\n if (isFalse(process.env.FARM_TELEMETRY)) {\n return { enabled: false, reason: \"FARM_TELEMETRY disables collection\" };\n }\n return {};\n}\n\nfunction isContinuousIntegration(): boolean {\n return (\n isTrue(process.env.CI) ||\n isTrue(process.env.GITHUB_ACTIONS) ||\n isTrue(process.env.BUILDKITE) ||\n isTrue(process.env.CIRCLECI)\n );\n}\n\nfunction isInteractive(): boolean {\n return process.stdin.isTTY === true && process.stdout.isTTY === true;\n}\n\nfunction getEndpoint(): string {\n const candidate = process.env.FARM_TELEMETRY_ENDPOINT || DEFAULT_TELEMETRY_ENDPOINT;\n try {\n const url = new URL(candidate);\n const isLocal = [\"localhost\", \"127.0.0.1\", \"::1\"].includes(url.hostname);\n if (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && isLocal)) {\n return DEFAULT_TELEMETRY_ENDPOINT;\n }\n return url.toString();\n } catch {\n return DEFAULT_TELEMETRY_ENDPOINT;\n }\n}\n\nasync function resolveState(): Promise<{\n config: FarmTelemetryConfig;\n enabled: boolean;\n active: boolean;\n source: FarmTelemetryStatus[\"source\"];\n reason?: string;\n}> {\n const { config, stored } = await readConfig();\n const environment = environmentDecision();\n const enabled = environment.enabled ?? config.enabled;\n const source =\n environment.enabled !== undefined ? \"environment\" : stored ? \"configuration\" : \"default\";\n\n if (!enabled) return { config, enabled, active: false, source, reason: environment.reason };\n if (environment.enabled === true) return { config, enabled, active: true, source };\n if (process.env.NODE_ENV === \"test\") {\n return { config, enabled, active: false, source, reason: \"test environments are skipped\" };\n }\n if (isContinuousIntegration()) {\n return { config, enabled, active: false, source, reason: \"CI environments are skipped\" };\n }\n if (!isInteractive()) {\n return {\n config,\n enabled,\n active: false,\n source,\n reason: \"non-interactive commands are skipped\",\n };\n }\n return { config, enabled, active: true, source };\n}\n\nexport async function getFarmTelemetryStatus(): Promise<FarmTelemetryStatus> {\n const state = await resolveState();\n return {\n enabled: state.enabled,\n active: state.active,\n source: state.source,\n endpoint: getEndpoint(),\n configFile: getFarmTelemetryConfigFile(),\n anonymousId: state.config.anonymousId,\n reason: state.reason,\n };\n}\n\nexport async function setFarmTelemetryEnabled(enabled: boolean): Promise<FarmTelemetryStatus> {\n const { config: current } = await readConfig();\n await writeConfig({\n version: TELEMETRY_SCHEMA_VERSION,\n enabled,\n noticeShown: true,\n anonymousId: enabled ? current.anonymousId || randomUUID() : undefined,\n });\n return getFarmTelemetryStatus();\n}\n\nexport async function showFarmTelemetryNotice(): Promise<void> {\n if (!isInteractive() || isContinuousIntegration() || process.env.NODE_ENV === \"test\") return;\n if (environmentDecision().enabled !== undefined) return;\n const { config } = await readConfig();\n if (config.noticeShown) return;\n process.stderr.write(\n `Farm.js collects anonymous CLI telemetry by default. Run \"farm telemetry disable\" to opt out.\\nLearn more: ${TELEMETRY_NOTICE_URL}\\n`,\n );\n await writeConfig({ ...config, noticeShown: true });\n}\n\nexport function resolveFarmTelemetryCommand(value: string): FarmTelemetryCommand | undefined {\n return (FARM_TELEMETRY_COMMANDS as readonly string[]).includes(value)\n ? (value as FarmTelemetryCommand)\n : undefined;\n}\n\nexport function resolveFarmCreateAppTelemetryCommand(\n value: string,\n): FarmCreateAppTelemetryCommand | undefined {\n return (FARM_CREATE_APP_TELEMETRY_COMMANDS as readonly string[]).includes(value)\n ? (value as FarmCreateAppTelemetryCommand)\n : undefined;\n}\n\nexport function trackFarmCommand(input: FarmCommandTelemetryInput): Promise<void> {\n return schedule(async () => {\n await showFarmTelemetryNotice();\n const deployTarget = allowlisted(input.deployTarget, FARM_TELEMETRY_DEPLOY_TARGETS);\n await track({\n eventType: \"command_invoked\",\n source: \"cli\",\n packageName: \"@farm.js/cli\",\n packageVersion: sanitizeVersion(input.packageVersion),\n command: input.command,\n ...(deployTarget ? { deployTarget } : {}),\n });\n });\n}\n\nexport function trackFarmCreateAppCommand(\n input: FarmCreateAppCommandTelemetryInput,\n): Promise<void> {\n return schedule(async () => {\n await showFarmTelemetryNotice();\n const command = allowlisted(input.command, FARM_CREATE_APP_TELEMETRY_COMMANDS);\n if (!command) return;\n await track({\n eventType: \"command_invoked\",\n source: \"create-app\",\n packageName: \"@farm.js/create-app\",\n packageVersion: sanitizeVersion(input.packageVersion),\n command,\n });\n });\n}\n\nexport function trackFarmProjectCreated(input: FarmProjectCreatedTelemetryInput): Promise<void> {\n return schedule(async () => {\n const template = allowlisted(input.template, FARM_TELEMETRY_TEMPLATES);\n const renderer = allowlisted(input.renderer, FARM_TELEMETRY_RENDERERS);\n const packageManager = allowlisted(input.packageManager, FARM_TELEMETRY_PACKAGE_MANAGERS);\n await track({\n eventType: \"project_created\",\n source: \"create-app\",\n packageName: \"@farm.js/create-app\",\n packageVersion: sanitizeVersion(input.packageVersion),\n ...(template ? { template } : {}),\n ...(renderer ? { renderer } : {}),\n ...(packageManager ? { packageManager } : {}),\n ...(typeof input.typescript === \"boolean\" ? { typescript: input.typescript } : {}),\n ...(typeof input.installedDependencies === \"boolean\"\n ? { installedDependencies: input.installedDependencies }\n : {}),\n });\n });\n}\n\nfunction schedule(delivery: () => Promise<void>): Promise<void> {\n const pending = Promise.resolve()\n .then(delivery)\n .catch(() => {\n // Telemetry is best-effort and must never surface as an unhandled rejection.\n });\n pendingDeliveries.add(pending);\n void pending.finally(() => pendingDeliveries.delete(pending));\n return Promise.resolve();\n}\n\n/** Wait for background telemetry. Intended for tests and explicit process shutdown hooks. */\nexport async function flushFarmTelemetry(): Promise<void> {\n telemetryFlushWaiters += 1;\n for (const timer of retryTimers) timer.ref?.();\n try {\n while (pendingDeliveries.size > 0) {\n await Promise.allSettled(pendingDeliveries);\n }\n } finally {\n telemetryFlushWaiters -= 1;\n if (telemetryFlushWaiters === 0) {\n for (const timer of retryTimers) timer.unref?.();\n }\n }\n}\n\nasync function track(event: FarmTelemetryEventInput): Promise<void> {\n try {\n const state = await resolveState();\n if (!state.active) return;\n const anonymousId = state.config.anonymousId || randomUUID();\n if (!state.config.anonymousId) {\n await writeConfig({ ...state.config, anonymousId });\n }\n const payload = {\n schemaVersion: TELEMETRY_SCHEMA_VERSION,\n eventId: randomUUID(),\n anonymousId,\n nodeMajor: Number.parseInt(process.versions.node.split(\".\")[0] || \"0\", 10),\n platform: normalizePlatform(process.platform),\n architecture: normalizeArchitecture(process.arch),\n ...event,\n } as FarmTelemetryEvent;\n await send(payload);\n } catch {\n // Telemetry is best-effort and must never make a Farm command fail.\n }\n}\n\nasync function send(payload: FarmTelemetryEvent): Promise<void> {\n for (let attempt = 0; attempt <= RETRY_DELAYS_MS.length; attempt += 1) {\n const result = await sendOnce(payload);\n if (result === \"delivered\" || result === \"rejected\") return;\n const delay = RETRY_DELAYS_MS[attempt];\n if (delay !== undefined) await wait(delay);\n }\n debug(\"delivery failed after retries\");\n}\n\nasync function sendOnce(payload: FarmTelemetryEvent): Promise<\"delivered\" | \"retry\" | \"rejected\"> {\n let endpoint: URL;\n try {\n endpoint = new URL(getEndpoint());\n } catch {\n debug(\"invalid endpoint URL\");\n return \"rejected\";\n }\n\n const requestTransport = endpoint.protocol === \"http:\" ? httpRequest : httpsRequest;\n if (endpoint.protocol !== \"http:\" && endpoint.protocol !== \"https:\") {\n debug(`unsupported endpoint protocol ${endpoint.protocol}`);\n return \"rejected\";\n }\n\n const body = JSON.stringify(payload);\n return new Promise((resolve) => {\n let settled = false;\n const finish = (result: \"delivered\" | \"retry\" | \"rejected\") => {\n if (settled) return;\n settled = true;\n clearTimeout(timeout);\n resolve(result);\n };\n const request = requestTransport(\n endpoint,\n {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"content-length\": Buffer.byteLength(body),\n },\n },\n (response) => {\n response.on(\"error\", () => {\n // The status code is sufficient; response bodies are never telemetry input.\n });\n response.resume();\n const status = response.statusCode ?? 0;\n if (status >= 200 && status < 300) return finish(\"delivered\");\n if (status === 408 || status === 425 || status === 429) {\n debug(`temporary HTTP ${status}; retrying`);\n return finish(\"retry\");\n }\n if (status >= 500) {\n debug(`server HTTP ${status}; retrying`);\n return finish(\"retry\");\n }\n debug(`event rejected with HTTP ${status}`);\n return finish(\"rejected\");\n },\n );\n const timeout = setTimeout(() => {\n request.destroy();\n debug(\"network request timed out; retrying\");\n finish(\"retry\");\n }, REQUEST_TIMEOUT_MS);\n timeout.unref?.();\n request.once(\"socket\", (socket) => socket.unref());\n request.once(\"error\", () => {\n debug(\"network request failed; retrying\");\n finish(\"retry\");\n });\n request.end(body);\n });\n}\n\nfunction wait(delay: number): Promise<void> {\n return new Promise((resolve) => {\n const timeout = setTimeout(() => {\n retryTimers.delete(timeout);\n resolve();\n }, delay);\n retryTimers.add(timeout);\n if (telemetryFlushWaiters === 0) timeout.unref?.();\n });\n}\n\nfunction debug(message: string): void {\n if (!isTrue(process.env.FARM_TELEMETRY_DEBUG)) return;\n process.stderr.write(`[farm.telemetry] ${message}\\n`);\n}\n\nfunction sanitizeVersion(value: string): string {\n return /^[0-9A-Za-z.+_-]{1,64}$/.test(value) ? value : \"unknown\";\n}\n\nfunction allowlisted<const T extends readonly string[]>(\n value: string | undefined,\n values: T,\n): T[number] | undefined {\n return value && (values as readonly string[]).includes(value) ? (value as T[number]) : undefined;\n}\n\nfunction normalizePlatform(value: NodeJS.Platform): FarmTelemetryEventBase[\"platform\"] {\n if (value === \"darwin\" || value === \"linux\") return value;\n if (value === \"win32\") return \"windows\";\n return \"other\";\n}\n\nfunction normalizeArchitecture(value: string): FarmTelemetryEventBase[\"architecture\"] {\n return value === \"arm64\" || value === \"x64\" ? value : \"other\";\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAa,0BAA0B;CACrC;CACA;CACA;CACA;CACA;CAC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