@cedarjs/telemetry 8.0.0-canary.3592 → 8.0.0-canary.3595
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/redact.d.ts +23 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +69 -0
- package/dist/sendTelemetry.d.ts.map +1 -1
- package/dist/sendTelemetry.js +2 -1
- package/dist/telemetry.d.ts +5 -1
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +7 -1
- package/package.json +3 -3
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an error (or any thrown value) into a message that is safe to send
|
|
3
|
+
* with telemetry.
|
|
4
|
+
*
|
|
5
|
+
* Only the first line is kept, because some errors include the full stack
|
|
6
|
+
* trace in the message. Then every word that could identify a user, their
|
|
7
|
+
* project or their infrastructure is replaced: anything containing `/`, `\`,
|
|
8
|
+
* `@` or `:`, and IPv4 addresses. Replacements are labelled `[url]`, `[host]`,
|
|
9
|
+
* `[path]` or `[redacted]`. Quoted paths are replaced as a whole, since they
|
|
10
|
+
* can contain spaces, and so are hostnames in DNS errors.
|
|
11
|
+
*
|
|
12
|
+
* Words that describe the failure without identifying anyone are kept:
|
|
13
|
+
* scoped package names (`@cedarjs/vite`), known specifiers (`node:fs`),
|
|
14
|
+
* version numbers, clock times and words that only end in a colon (`Error:`).
|
|
15
|
+
* What is left is the shape of the error, e.g.
|
|
16
|
+
* `ENOENT: no such file or directory, open '[path]'`.
|
|
17
|
+
*
|
|
18
|
+
* The same function is exported from `@cedarjs/cli-helpers/telemetry`.
|
|
19
|
+
* `@cedarjs/cli-helpers` depends on this package, so this package keeps its
|
|
20
|
+
* own copy instead of importing it from there.
|
|
21
|
+
*/
|
|
22
|
+
export declare function redactErrorMessage(error: unknown): string;
|
|
23
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAwBzD"}
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function redactErrorMessage(error) {
|
|
2
|
+
const message = error instanceof Error ? error.message : typeof error === "string" ? error : String(error);
|
|
3
|
+
return (message.split("\n")[0] || "Unknown error").replace(
|
|
4
|
+
/(['"`])([^'"`\\/\n]*[\\/][^'"`\n]*)\1/g,
|
|
5
|
+
(_match, quote, inner) => `${quote}${isSafeWord(inner) ? inner : placeholderFor(inner)}${quote}`
|
|
6
|
+
).replace(/\b(ENOTFOUND|EAI_AGAIN)\s+[^\s'"`]+/g, "$1 [host]").replace(/\S+/g, redactWord);
|
|
7
|
+
}
|
|
8
|
+
const SCOPED_PACKAGE = /^@[a-z0-9~-][\w.~-]*\/[a-z0-9~-][\w.~-]*(?:\/[\w.-]+)*(?:@[\w.^~*<>=-]+)?$/i;
|
|
9
|
+
const KNOWN_SPECIFIER = /^(?:node|npm|workspace|catalog):[\w.^~*<>=-]*$/;
|
|
10
|
+
const CLOCK_TIME = /^\d{1,2}:\d{2}(?::\d{2})?$/;
|
|
11
|
+
const IPV4 = /(?:^|[^\d.])\d{1,3}(?:\.\d{1,3}){3}(?![.\d])/;
|
|
12
|
+
const IPV6 = /^\[?[\da-f]*:[\da-f]*:[\da-f:]*\]?(?::\d+)?$/i;
|
|
13
|
+
const HOST_AND_PORT = /^[\w.-]+:\d+$/;
|
|
14
|
+
const LEADING_PUNCTUATION = /* @__PURE__ */ new Set(["(", "'", '"', "`", "<", "[", "{"]);
|
|
15
|
+
const TRAILING_PUNCTUATION = /* @__PURE__ */ new Set([
|
|
16
|
+
")",
|
|
17
|
+
"'",
|
|
18
|
+
'"',
|
|
19
|
+
"`",
|
|
20
|
+
">",
|
|
21
|
+
"]",
|
|
22
|
+
"}",
|
|
23
|
+
",",
|
|
24
|
+
";",
|
|
25
|
+
".",
|
|
26
|
+
"!",
|
|
27
|
+
"?"
|
|
28
|
+
]);
|
|
29
|
+
function isSafeWord(word) {
|
|
30
|
+
if (!/[/\\@:]/.test(word) && !IPV4.test(word)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return SCOPED_PACKAGE.test(word) || KNOWN_SPECIFIER.test(word) || word.startsWith("npm:") && SCOPED_PACKAGE.test(word.slice(4)) || CLOCK_TIME.test(word);
|
|
34
|
+
}
|
|
35
|
+
function placeholderFor(word) {
|
|
36
|
+
if (word.includes("://")) {
|
|
37
|
+
return "[url]";
|
|
38
|
+
}
|
|
39
|
+
if (IPV4.test(word) || IPV6.test(word) || HOST_AND_PORT.test(word)) {
|
|
40
|
+
return "[host]";
|
|
41
|
+
}
|
|
42
|
+
if (/[/\\]/.test(word)) {
|
|
43
|
+
return "[path]";
|
|
44
|
+
}
|
|
45
|
+
return "[redacted]";
|
|
46
|
+
}
|
|
47
|
+
function redactWord(word) {
|
|
48
|
+
let start = 0;
|
|
49
|
+
let end = word.length;
|
|
50
|
+
while (end > start && TRAILING_PUNCTUATION.has(word[end - 1])) {
|
|
51
|
+
end--;
|
|
52
|
+
}
|
|
53
|
+
const withoutTrailing = word.slice(0, end);
|
|
54
|
+
if (!CLOCK_TIME.test(withoutTrailing) && IPV6.test(withoutTrailing)) {
|
|
55
|
+
return "[host]" + word.slice(end);
|
|
56
|
+
}
|
|
57
|
+
while (start < end && LEADING_PUNCTUATION.has(word[start])) {
|
|
58
|
+
start++;
|
|
59
|
+
}
|
|
60
|
+
const core = word.slice(start, end);
|
|
61
|
+
const checked = core.endsWith(":") ? core.slice(0, -1) : core;
|
|
62
|
+
if (checked === "" || isSafeWord(checked)) {
|
|
63
|
+
return word;
|
|
64
|
+
}
|
|
65
|
+
return word.slice(0, start) + placeholderFor(core) + word.slice(end);
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
redactErrorMessage
|
|
69
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendTelemetry.d.ts","sourceRoot":"","sources":["../src/sendTelemetry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sendTelemetry.d.ts","sourceRoot":"","sources":["../src/sendTelemetry.ts"],"names":[],"mappings":"AAeA,UAAU,qBAAqB;IAC7B,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,EAAE,MAAM,EAAE,CAAA;KACpB,CAAA;IACD,CAAC,EAAE;QACD,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,MAAM,EAAE;QACN,SAAS,CAAC,EAAE,KAAK,CAAA;QACjB,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,IAAI,EAAE;QACJ,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;QACpB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,EAAE,MAAM,EAAE,CAAA;KACpB,CAAA;CACF;AA8ED,eAAO,MAAM,YAAY,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,EAAE,GAAG,MAAM,EAAE,CAAC,WAyCjE,CAAA;AAyGD,eAAO,MAAM,aAAa,qBAsCzB,CAAA"}
|
package/dist/sendTelemetry.js
CHANGED
|
@@ -8,6 +8,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
8
8
|
import yargsParser from "yargs/yargs";
|
|
9
9
|
import { getRawConfig, getPaths } from "@cedarjs/project-config";
|
|
10
10
|
import { RWProject } from "@cedarjs/structure/dist/model/RWProject";
|
|
11
|
+
import { redactErrorMessage } from "./redact.js";
|
|
11
12
|
const SENSITIVE_ARG_POSITIONS = {
|
|
12
13
|
exec: {
|
|
13
14
|
positions: [1],
|
|
@@ -127,7 +128,7 @@ const buildPayload = async () => {
|
|
|
127
128
|
};
|
|
128
129
|
if (errorFlag) {
|
|
129
130
|
payload.type = "error";
|
|
130
|
-
payload.error = errorFlag
|
|
131
|
+
payload.error = redactErrorMessage(errorFlag);
|
|
131
132
|
}
|
|
132
133
|
const project = new RWProject();
|
|
133
134
|
const routes = project.getRouter().routes;
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function quoteForWindowsShell(arg: string): string;
|
|
15
15
|
export declare const timedTelemetry: (argv: string[], options: Record<string, unknown>, func: (...args: any[]) => any) => Promise<any>;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Sends an error telemetry event. Only a redacted version of the error message
|
|
18
|
+
* is sent, see `redactErrorMessage`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const errorTelemetry: (argv: string[], error: unknown) => Promise<void>;
|
|
17
21
|
export declare const telemetryMiddleware: () => Promise<void>;
|
|
18
22
|
//# sourceMappingURL=telemetry.d.ts.map
|
package/dist/telemetry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,UAuB/C;AAsDD,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,EAAE,EACd,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,iBAuB9B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAU,MAAM,MAAM,EAAE,EAAE,OAAO,OAAO,kBAclE,CAAA;AAGD,eAAO,MAAM,mBAAmB,qBAS/B,CAAA"}
|
package/dist/telemetry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
2
|
import os from "os";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { redactErrorMessage } from "./redact.js";
|
|
4
5
|
function quoteForWindowsShell(arg) {
|
|
5
6
|
let quoted = '"';
|
|
6
7
|
let backslashes = 0;
|
|
@@ -64,7 +65,12 @@ const errorTelemetry = async (argv, error) => {
|
|
|
64
65
|
if (process.env.CEDAR_DISABLE_TELEMETRY || process.env.REDWOOD_DISABLE_TELEMETRY) {
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
67
|
-
spawnProcess(
|
|
68
|
+
spawnProcess(
|
|
69
|
+
"--argv",
|
|
70
|
+
JSON.stringify(argv),
|
|
71
|
+
"--error",
|
|
72
|
+
JSON.stringify(redactErrorMessage(error))
|
|
73
|
+
);
|
|
68
74
|
};
|
|
69
75
|
const telemetryMiddleware = async () => {
|
|
70
76
|
if (process.env.CEDAR_DISABLE_TELEMETRY || process.env.REDWOOD_DISABLE_TELEMETRY) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/telemetry",
|
|
3
|
-
"version": "8.0.0-canary.
|
|
3
|
+
"version": "8.0.0-canary.3595",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"test:watch": "vitest watch"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@cedarjs/project-config": "8.0.0-canary.
|
|
26
|
-
"@cedarjs/structure": "8.0.0-canary.
|
|
25
|
+
"@cedarjs/project-config": "8.0.0-canary.3595",
|
|
26
|
+
"@cedarjs/structure": "8.0.0-canary.3595",
|
|
27
27
|
"@whatwg-node/fetch": "0.12.1",
|
|
28
28
|
"ci-info": "4.4.0",
|
|
29
29
|
"envinfo": "7.21.0",
|