@astrojs/telemetry
Advanced tools
Comparing version 0.0.0-imgcache-20220929145446 to 0.0.0-sanitize-filenames-20230901201147
@@ -33,2 +33,5 @@ import dget from "dlv"; | ||
} | ||
dir; | ||
file; | ||
_store; | ||
get store() { | ||
@@ -39,6 +42,9 @@ if (this._store) | ||
if (fs.existsSync(this.file)) { | ||
this._store = JSON.parse(fs.readFileSync(this.file).toString()); | ||
} else { | ||
const store = {}; | ||
this._store = store; | ||
try { | ||
this._store = JSON.parse(fs.readFileSync(this.file).toString()); | ||
} catch { | ||
} | ||
} | ||
if (!this._store) { | ||
this._store = {}; | ||
this.write(); | ||
@@ -45,0 +51,0 @@ } |
@@ -9,8 +9,13 @@ import { isCI } from "ci-info"; | ||
import { getSystemInfo } from "./system-info.js"; | ||
const VALID_TELEMETRY_NOTICE_DATE = "2023-08-25"; | ||
class AstroTelemetry { | ||
constructor(opts) { | ||
this.opts = opts; | ||
this.config = new GlobalConfig({ name: "astro" }); | ||
this.debug = debug("astro:telemetry"); | ||
} | ||
_anonymousSessionId; | ||
_anonymousProjectInfo; | ||
config = new GlobalConfig({ name: "astro" }); | ||
debug = debug("astro:telemetry"); | ||
isCI = isCI; | ||
env = process.env; | ||
get astroVersion() { | ||
@@ -23,10 +28,15 @@ return this.opts.astroVersion; | ||
get ASTRO_TELEMETRY_DISABLED() { | ||
return process.env.ASTRO_TELEMETRY_DISABLED; | ||
return this.env.ASTRO_TELEMETRY_DISABLED; | ||
} | ||
get TELEMETRY_DISABLED() { | ||
return process.env.TELEMETRY_DISABLED; | ||
return this.env.TELEMETRY_DISABLED; | ||
} | ||
/** | ||
* Get value from either the global config or the provided fallback. | ||
* If value is not set, the fallback is saved to the global config, | ||
* persisted for later sessions. | ||
*/ | ||
getConfigWithFallback(key, getValue) { | ||
const currentValue = this.config.get(key); | ||
if (currentValue) { | ||
if (currentValue !== void 0) { | ||
return currentValue; | ||
@@ -52,3 +62,3 @@ } | ||
get anonymousProjectInfo() { | ||
this._anonymousProjectInfo = this._anonymousProjectInfo || getProjectInfo(isCI); | ||
this._anonymousProjectInfo = this._anonymousProjectInfo || getProjectInfo(this.isCI); | ||
return this._anonymousProjectInfo; | ||
@@ -68,12 +78,22 @@ } | ||
} | ||
isValidNotice() { | ||
if (!this.notifyDate) | ||
return false; | ||
const current = Number(this.notifyDate); | ||
const valid = new Date(VALID_TELEMETRY_NOTICE_DATE).valueOf(); | ||
return current > valid; | ||
} | ||
async notify(callback) { | ||
if (this.isDisabled || isCI) { | ||
if (this.isDisabled || this.isCI) { | ||
this.debug(`[notify] telemetry has been disabled`); | ||
return; | ||
} | ||
if (this.notifyDate) { | ||
if (this.isValidNotice()) { | ||
this.debug(`[notify] last notified on ${this.notifyDate}`); | ||
return; | ||
} | ||
const enabled = await callback(); | ||
this.config.set(KEY.TELEMETRY_NOTIFY_DATE, Date.now().toString()); | ||
this.config.set(KEY.TELEMETRY_NOTIFY_DATE, (/* @__PURE__ */ new Date()).valueOf().toString()); | ||
this.config.set(KEY.TELEMETRY_ENABLED, enabled); | ||
this.debug(`[notify] telemetry has been ${enabled ? "enabled" : "disabled"}`); | ||
} | ||
@@ -86,3 +106,3 @@ async record(event = []) { | ||
if (this.isDisabled) { | ||
this.debug("telemetry disabled"); | ||
this.debug("[record] telemetry has been disabled"); | ||
return Promise.resolve(); | ||
@@ -89,0 +109,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import fetch from "node-fetch"; | ||
const ASTRO_TELEMETRY_ENDPOINT = `https://telemetry.astro.build/api/v1/record`; | ||
import { fetch } from "undici"; | ||
function post(body) { | ||
@@ -4,0 +4,0 @@ return fetch(ASTRO_TELEMETRY_ENDPOINT, { |
@@ -1,2 +0,2 @@ | ||
import { execSync } from "child_process"; | ||
import { execSync } from "node:child_process"; | ||
import { createHash } from "node:crypto"; | ||
@@ -49,4 +49,4 @@ import detectPackageManager from "which-pm-runs"; | ||
...projectId, | ||
packageManager: packageManager == null ? void 0 : packageManager.name, | ||
packageManagerVersion: packageManager == null ? void 0 : packageManager.version | ||
packageManager: packageManager?.name, | ||
packageManagerVersion: packageManager?.version | ||
}; | ||
@@ -53,0 +53,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { isCI, name as ciName } from "ci-info"; | ||
import { name as ciName, isCI } from "ci-info"; | ||
import isDocker from "is-docker"; | ||
@@ -12,8 +12,11 @@ import isWSL from "is-wsl"; | ||
meta = { | ||
// Version information | ||
nodeVersion: process.version.replace(/^v?/, ""), | ||
viteVersion: versions.viteVersion, | ||
astroVersion: versions.astroVersion, | ||
// Software information | ||
systemPlatform: os.platform(), | ||
systemRelease: os.release(), | ||
systemArchitecture: os.arch(), | ||
// Machine information | ||
cpuCount: cpus.length, | ||
@@ -23,2 +26,3 @@ cpuModel: cpus.length ? cpus[0].model : null, | ||
memoryInMb: Math.trunc(os.totalmem() / Math.pow(1024, 2)), | ||
// Environment information | ||
isDocker: isDocker(), | ||
@@ -25,0 +29,0 @@ isWSL, |
@@ -1,6 +0,6 @@ | ||
export declare type AstroTelemetryOptions = { | ||
export type AstroTelemetryOptions = { | ||
astroVersion: string; | ||
viteVersion: string; | ||
}; | ||
export declare type TelemetryEvent = { | ||
export type TelemetryEvent = { | ||
eventName: string; | ||
@@ -15,2 +15,4 @@ payload: Record<string, any>; | ||
private debug; | ||
private isCI; | ||
private env; | ||
private get astroVersion(); | ||
@@ -35,4 +37,5 @@ private get viteVersion(); | ||
clear(): void; | ||
notify(callback: () => Promise<boolean>): Promise<void>; | ||
isValidNotice(): boolean; | ||
notify(callback: () => boolean | Promise<boolean>): Promise<void>; | ||
record(event?: TelemetryEvent | TelemetryEvent[]): Promise<any>; | ||
} |
@@ -25,3 +25,3 @@ /// <reference types="node" /> | ||
*/ | ||
export declare type SystemInfo = { | ||
export type SystemInfo = { | ||
systemPlatform: NodeJS.Platform; | ||
@@ -28,0 +28,0 @@ systemRelease: string; |
{ | ||
"name": "@astrojs/telemetry", | ||
"version": "0.0.0-imgcache-20220929145446", | ||
"version": "0.0.0-sanitize-filenames-20230901201147", | ||
"type": "module", | ||
@@ -16,3 +16,6 @@ "types": "./dist/types/index.d.ts", | ||
"exports": { | ||
".": "./dist/index.js", | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
@@ -24,3 +27,3 @@ }, | ||
"dependencies": { | ||
"ci-info": "^3.3.1", | ||
"ci-info": "^3.8.0", | ||
"debug": "^4.3.4", | ||
@@ -30,17 +33,17 @@ "dlv": "^1.1.3", | ||
"is-docker": "^3.0.0", | ||
"is-wsl": "^2.2.0", | ||
"node-fetch": "^3.2.5", | ||
"is-wsl": "^3.0.0", | ||
"undici": "^5.23.0", | ||
"which-pm-runs": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/debug": "^4.1.7", | ||
"@types/debug": "^4.1.8", | ||
"@types/dlv": "^1.1.2", | ||
"@types/node": "^14.18.21", | ||
"@types/node": "^18.17.8", | ||
"@types/which-pm-runs": "^1.0.0", | ||
"astro-scripts": "0.0.8", | ||
"chai": "^4.3.6", | ||
"mocha": "^9.2.2" | ||
"chai": "^4.3.7", | ||
"mocha": "^10.2.0", | ||
"astro-scripts": "0.0.14" | ||
}, | ||
"engines": { | ||
"node": "^14.18.0 || >=16.12.0" | ||
"node": ">=18.14.1" | ||
}, | ||
@@ -47,0 +50,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
20315
483
3
1
+ Addedundici@^5.23.0
+ Added@fastify/busboy@2.1.1(transitive)
+ Addedis-inside-container@1.0.0(transitive)
+ Addedis-wsl@3.1.0(transitive)
+ Addedundici@5.28.4(transitive)
- Removednode-fetch@^3.2.5
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removedis-docker@2.2.1(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
Updatedci-info@^3.8.0
Updatedis-wsl@^3.0.0