Collect project meta info (#3587)
* chore: add project meta * Update index.ts
This commit is contained in:
parent
7832c6a260
commit
5ab9d573f6
3 changed files with 103 additions and 0 deletions
|
@ -32,6 +32,7 @@
|
|||
"dlv": "^1.1.3",
|
||||
"dset": "^3.1.2",
|
||||
"escalade": "^3.1.1",
|
||||
"git-up": "^4.0.5",
|
||||
"is-docker": "^3.0.0",
|
||||
"is-wsl": "^2.2.0",
|
||||
"node-fetch": "^3.2.5"
|
||||
|
|
|
@ -3,6 +3,8 @@ import { createHash, randomBytes } from 'node:crypto';
|
|||
|
||||
import { isCI } from 'ci-info';
|
||||
import debug from 'debug';
|
||||
// @ts-ignore
|
||||
import gitUp from 'git-up';
|
||||
|
||||
import { getAnonymousMeta } from './anonymous-meta.js';
|
||||
import { Config } from './config.js';
|
||||
|
@ -10,6 +12,7 @@ import * as KEY from './keys.js';
|
|||
import { post } from './post.js';
|
||||
import { getRawProjectId } from './project-id.js';
|
||||
|
||||
|
||||
export interface AstroTelemetryOptions {
|
||||
version: string;
|
||||
}
|
||||
|
@ -19,6 +22,7 @@ export type TelemetryEvent = { eventName: string; payload: Record<string, any> }
|
|||
interface EventContext {
|
||||
anonymousId: string;
|
||||
projectId: string;
|
||||
projectMetadata: any;
|
||||
sessionId: string;
|
||||
}
|
||||
|
||||
|
@ -77,6 +81,12 @@ export class AstroTelemetry {
|
|||
return this.getWithFallback(KEY.TELEMETRY_NOTIFY_DATE, '');
|
||||
}
|
||||
|
||||
private hash(payload: BinaryLike): string {
|
||||
const hash = createHash('sha256');
|
||||
hash.update(payload);
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
// Create a ONE-WAY hash so there is no way for Astro to decode the value later.
|
||||
private oneWayHash(payload: BinaryLike): string {
|
||||
const hash = createHash('sha256');
|
||||
|
@ -93,6 +103,18 @@ export class AstroTelemetry {
|
|||
return this.oneWayHash(this.rawProjectId);
|
||||
}
|
||||
|
||||
private get projectMetadata(): undefined | { owner: string, name: string } {
|
||||
const projectId = this.rawProjectId;
|
||||
if (projectId === process.cwd()) {
|
||||
return;
|
||||
}
|
||||
const { pathname, resource } = gitUp(projectId);
|
||||
const parts = pathname.split('/').slice(1);
|
||||
const owner = `${resource}${parts[0]}`;
|
||||
const name = parts[1].replace('.git', '');
|
||||
return { owner: this.hash(owner), name: this.hash(name) };
|
||||
}
|
||||
|
||||
private get isDisabled(): boolean {
|
||||
if (Boolean(this.ASTRO_TELEMETRY_DISABLED || this.TELEMETRY_DISABLED)) {
|
||||
return true;
|
||||
|
@ -154,6 +176,7 @@ export class AstroTelemetry {
|
|||
const context: EventContext = {
|
||||
anonymousId: this.anonymousId,
|
||||
projectId: this.projectId,
|
||||
projectMetadata: this.projectMetadata,
|
||||
sessionId: this.sessionId,
|
||||
};
|
||||
const meta = getAnonymousMeta(this.astroVersion);
|
||||
|
|
|
@ -1981,6 +1981,7 @@ importers:
|
|||
dlv: ^1.1.3
|
||||
dset: ^3.1.2
|
||||
escalade: ^3.1.1
|
||||
git-up: ^4.0.5
|
||||
is-docker: ^3.0.0
|
||||
is-wsl: ^2.2.0
|
||||
node-fetch: ^3.2.5
|
||||
|
@ -1990,6 +1991,7 @@ importers:
|
|||
dlv: 1.1.3
|
||||
dset: 3.1.2
|
||||
escalade: 3.1.1
|
||||
git-up: 4.0.5
|
||||
is-docker: 3.0.0
|
||||
is-wsl: 2.2.0
|
||||
node-fetch: 3.2.5
|
||||
|
@ -8197,6 +8199,11 @@ packages:
|
|||
character-entities: 2.0.1
|
||||
dev: false
|
||||
|
||||
/decode-uri-component/0.2.0:
|
||||
resolution: {integrity: sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og==}
|
||||
engines: {node: '>=0.10'}
|
||||
dev: false
|
||||
|
||||
/decompress-response/6.0.0:
|
||||
resolution: {integrity: sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==}
|
||||
engines: {node: '>=10'}
|
||||
|
@ -9081,6 +9088,11 @@ packages:
|
|||
dependencies:
|
||||
to-regex-range: 5.0.1
|
||||
|
||||
/filter-obj/1.1.0:
|
||||
resolution: {integrity: sha512-8rXg1ZnX7xzy2NGDVkBVaAy+lSlPNwad13BtgSlLuxfIslyt5Vg64U7tFcCt4WS1R0hvtnQybT/IyCkGZ3DpXQ==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/find-up/4.1.0:
|
||||
resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==}
|
||||
engines: {node: '>=8'}
|
||||
|
@ -9298,6 +9310,13 @@ packages:
|
|||
- supports-color
|
||||
dev: true
|
||||
|
||||
/git-up/4.0.5:
|
||||
resolution: {integrity: sha512-YUvVDg/vX3d0syBsk/CKUTib0srcQME0JyHkL5BaYdwLsiCslPWmDSi8PUMo9pXYjrryMcmsCoCgsTpSCJEQaA==}
|
||||
dependencies:
|
||||
is-ssh: 1.3.3
|
||||
parse-url: 6.0.0
|
||||
dev: false
|
||||
|
||||
/github-from-package/0.0.0:
|
||||
resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==}
|
||||
dev: true
|
||||
|
@ -9991,6 +10010,12 @@ packages:
|
|||
dependencies:
|
||||
call-bind: 1.0.2
|
||||
|
||||
/is-ssh/1.3.3:
|
||||
resolution: {integrity: sha512-NKzJmQzJfEEma3w5cJNcUMxoXfDjz0Zj0eyCalHn2E6VOwlzjZo0yuO2fcBSf8zhFuVCL/82/r5gRcoi6aEPVQ==}
|
||||
dependencies:
|
||||
protocols: 1.4.8
|
||||
dev: false
|
||||
|
||||
/is-stream/2.0.1:
|
||||
resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==}
|
||||
engines: {node: '>=8'}
|
||||
|
@ -11163,6 +11188,11 @@ packages:
|
|||
resolution: {integrity: sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
/normalize-url/6.1.0:
|
||||
resolution: {integrity: sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==}
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
/not/0.1.0:
|
||||
resolution: {integrity: sha512-5PDmaAsVfnWUgTUbJ3ERwn7u79Z0dYxN9ErxCpVJJqe2RK0PJ3z+iFUxuqjwtlDDegXvtWoxD/3Fzxox7tFGWA==}
|
||||
|
||||
|
@ -11463,6 +11493,24 @@ packages:
|
|||
unist-util-visit-children: 1.1.4
|
||||
dev: false
|
||||
|
||||
/parse-path/4.0.4:
|
||||
resolution: {integrity: sha512-Z2lWUis7jlmXC1jeOG9giRO2+FsuyNipeQ43HAjqAZjwSe3SEf+q/84FGPHoso3kyntbxa4c4i77t3m6fGf8cw==}
|
||||
dependencies:
|
||||
is-ssh: 1.3.3
|
||||
protocols: 1.4.8
|
||||
qs: 6.10.5
|
||||
query-string: 6.14.1
|
||||
dev: false
|
||||
|
||||
/parse-url/6.0.0:
|
||||
resolution: {integrity: sha512-cYyojeX7yIIwuJzledIHeLUBVJ6COVLeT4eF+2P6aKVzwvgKQPndCBv3+yQ7pcWjqToYwaligxzSYNNmGoMAvw==}
|
||||
dependencies:
|
||||
is-ssh: 1.3.3
|
||||
normalize-url: 6.1.0
|
||||
parse-path: 4.0.4
|
||||
protocols: 1.4.8
|
||||
dev: false
|
||||
|
||||
/parse5-htmlparser2-tree-adapter/7.0.0:
|
||||
resolution: {integrity: sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==}
|
||||
dependencies:
|
||||
|
@ -11755,6 +11803,10 @@ packages:
|
|||
/property-information/6.1.1:
|
||||
resolution: {integrity: sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==}
|
||||
|
||||
/protocols/1.4.8:
|
||||
resolution: {integrity: sha512-IgjKyaUSjsROSO8/D49Ab7hP8mJgTYcqApOqdPhLoPxAplXmkp+zRvsrSQjFn5by0rhm4VH0GAUELIPpx7B1yg==}
|
||||
dev: false
|
||||
|
||||
/proxy-agent/5.0.0:
|
||||
resolution: {integrity: sha512-gkH7BkvLVkSfX9Dk27W6TyNOWWZWRilRfk1XxGNWOYJ2TuedAv1yFpCaU9QSBmBe716XOTNpYNOzhysyw8xn7g==}
|
||||
engines: {node: '>= 8'}
|
||||
|
@ -11791,6 +11843,23 @@ packages:
|
|||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/qs/6.10.5:
|
||||
resolution: {integrity: sha512-O5RlPh0VFtR78y79rgcgKK4wbAI0C5zGVLztOIdpWX6ep368q5Hv6XRxDvXuZ9q3C6v+e3n8UfZZJw7IIG27eQ==}
|
||||
engines: {node: '>=0.6'}
|
||||
dependencies:
|
||||
side-channel: 1.0.4
|
||||
dev: false
|
||||
|
||||
/query-string/6.14.1:
|
||||
resolution: {integrity: sha512-XDxAeVmpfu1/6IjyT/gXHOl+S0vQ9owggJ30hhWKdHAsNPOcasn5o9BW0eejZqL2e4vMjhAxoW3jVHcD6mbcYw==}
|
||||
engines: {node: '>=6'}
|
||||
dependencies:
|
||||
decode-uri-component: 0.2.0
|
||||
filter-obj: 1.1.0
|
||||
split-on-first: 1.1.0
|
||||
strict-uri-encode: 2.0.0
|
||||
dev: false
|
||||
|
||||
/queue-microtask/1.2.3:
|
||||
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
|
||||
|
||||
|
@ -12588,6 +12657,11 @@ packages:
|
|||
resolution: {integrity: sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g==}
|
||||
dev: true
|
||||
|
||||
/split-on-first/1.1.0:
|
||||
resolution: {integrity: sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==}
|
||||
engines: {node: '>=6'}
|
||||
dev: false
|
||||
|
||||
/sprintf-js/1.0.3:
|
||||
resolution: {integrity: sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=}
|
||||
|
||||
|
@ -12606,6 +12680,11 @@ packages:
|
|||
mixme: 0.5.4
|
||||
dev: true
|
||||
|
||||
/strict-uri-encode/2.0.0:
|
||||
resolution: {integrity: sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ==}
|
||||
engines: {node: '>=4'}
|
||||
dev: false
|
||||
|
||||
/string-width/1.0.2:
|
||||
resolution: {integrity: sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
|
Loading…
Reference in a new issue