@tinacms/metrics 1.1.0 → 2.0.1
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.js +48 -86
- package/package.json +3 -6
package/dist/index.js
CHANGED
|
@@ -1,46 +1,11 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/index.ts
|
|
30
|
-
var index_exports = {};
|
|
31
|
-
__export(index_exports, {
|
|
32
|
-
Telemetry: () => Telemetry
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
|
|
36
1
|
// src/telemetry/telemetry.ts
|
|
37
|
-
|
|
2
|
+
import { createHash } from "crypto";
|
|
38
3
|
|
|
39
4
|
// src/telemetry/getId.ts
|
|
40
|
-
|
|
5
|
+
import { execSync } from "child_process";
|
|
41
6
|
function _getProjectIdByGit() {
|
|
42
7
|
try {
|
|
43
|
-
const originBuffer =
|
|
8
|
+
const originBuffer = execSync(
|
|
44
9
|
`git config --local --get remote.origin.url`,
|
|
45
10
|
{
|
|
46
11
|
timeout: 1e3,
|
|
@@ -56,16 +21,13 @@ function getID() {
|
|
|
56
21
|
return _getProjectIdByGit() || process.env.REPOSITORY_URL || process.cwd();
|
|
57
22
|
}
|
|
58
23
|
|
|
59
|
-
// src/telemetry/telemetry.ts
|
|
60
|
-
var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
|
|
61
|
-
|
|
62
24
|
// src/telemetry/getVersion.ts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
25
|
+
import fse from "fs-extra";
|
|
26
|
+
import { execSync as execSync2 } from "child_process";
|
|
27
|
+
import { join } from "path";
|
|
66
28
|
function _executeCommand(cmd) {
|
|
67
29
|
try {
|
|
68
|
-
const originBuffer = (
|
|
30
|
+
const originBuffer = execSync2(cmd, {
|
|
69
31
|
timeout: 1e3,
|
|
70
32
|
stdio: `pipe`
|
|
71
33
|
});
|
|
@@ -77,9 +39,7 @@ function _executeCommand(cmd) {
|
|
|
77
39
|
var _getPack = (rootDir) => {
|
|
78
40
|
let pack = {};
|
|
79
41
|
try {
|
|
80
|
-
const rawJSON = (
|
|
81
|
-
(0, import_path.join)(rootDir, "package.json")
|
|
82
|
-
).toString();
|
|
42
|
+
const rawJSON = fse.readFileSync(join(rootDir, "package.json")).toString();
|
|
83
43
|
pack = JSON.parse(rawJSON);
|
|
84
44
|
} catch (_e) {
|
|
85
45
|
}
|
|
@@ -105,54 +65,56 @@ var getNpmVersion = () => {
|
|
|
105
65
|
// src/telemetry/telemetry.ts
|
|
106
66
|
var TINA_METRICS_ENDPOINT = "https://metrics.tina.io/record";
|
|
107
67
|
var Telemetry = class {
|
|
68
|
+
// private config: Conf<Record<string, unknown>>
|
|
69
|
+
projectIDRaw;
|
|
70
|
+
_disabled;
|
|
108
71
|
constructor({ disabled }) {
|
|
109
|
-
this.oneWayHash = (payload) => {
|
|
110
|
-
const hash = (0, import_crypto.createHash)("sha256");
|
|
111
|
-
hash.update(payload);
|
|
112
|
-
return hash.digest("hex");
|
|
113
|
-
};
|
|
114
|
-
this.submitRecord = async ({ event }) => {
|
|
115
|
-
if (this.isDisabled) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
const id = this.projectId;
|
|
120
|
-
const body = {
|
|
121
|
-
partitionKey: id,
|
|
122
|
-
data: {
|
|
123
|
-
anonymousId: id,
|
|
124
|
-
event: event.name,
|
|
125
|
-
properties: {
|
|
126
|
-
...event,
|
|
127
|
-
nodeVersion: process.version,
|
|
128
|
-
tinaCliVersion: getTinaCliVersion(),
|
|
129
|
-
tinaVersion: getTinaVersion(),
|
|
130
|
-
yarnVersion: getYarnVersion(),
|
|
131
|
-
npmVersion: getNpmVersion(),
|
|
132
|
-
CI: Boolean(process.env.CI)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
await (0, import_isomorphic_fetch.default)(TINA_METRICS_ENDPOINT, {
|
|
137
|
-
method: "POST",
|
|
138
|
-
body: JSON.stringify(body),
|
|
139
|
-
headers: { "content-type": "application/json" }
|
|
140
|
-
});
|
|
141
|
-
} catch (_e) {
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
72
|
this.projectIDRaw = getID();
|
|
145
73
|
const { NO_TELEMETRY } = process.env;
|
|
146
74
|
this._disabled = NO_TELEMETRY === "1" || NO_TELEMETRY === "true" || Boolean(disabled);
|
|
147
75
|
}
|
|
76
|
+
oneWayHash = (payload) => {
|
|
77
|
+
const hash = createHash("sha256");
|
|
78
|
+
hash.update(payload);
|
|
79
|
+
return hash.digest("hex");
|
|
80
|
+
};
|
|
148
81
|
get projectId() {
|
|
149
82
|
return this.oneWayHash(this.projectIDRaw);
|
|
150
83
|
}
|
|
151
84
|
get isDisabled() {
|
|
152
85
|
return this._disabled;
|
|
153
86
|
}
|
|
87
|
+
submitRecord = async ({ event }) => {
|
|
88
|
+
if (this.isDisabled) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const id = this.projectId;
|
|
93
|
+
const body = {
|
|
94
|
+
partitionKey: id,
|
|
95
|
+
data: {
|
|
96
|
+
anonymousId: id,
|
|
97
|
+
event: event.name,
|
|
98
|
+
properties: {
|
|
99
|
+
...event,
|
|
100
|
+
nodeVersion: process.version,
|
|
101
|
+
tinaCliVersion: getTinaCliVersion(),
|
|
102
|
+
tinaVersion: getTinaVersion(),
|
|
103
|
+
yarnVersion: getYarnVersion(),
|
|
104
|
+
npmVersion: getNpmVersion(),
|
|
105
|
+
CI: Boolean(process.env.CI)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
await fetch(TINA_METRICS_ENDPOINT, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
body: JSON.stringify(body),
|
|
112
|
+
headers: { "content-type": "application/json" }
|
|
113
|
+
});
|
|
114
|
+
} catch (_e) {
|
|
115
|
+
}
|
|
116
|
+
};
|
|
154
117
|
};
|
|
155
|
-
|
|
156
|
-
0 && (module.exports = {
|
|
118
|
+
export {
|
|
157
119
|
Telemetry
|
|
158
|
-
}
|
|
120
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/metrics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"typings": "dist/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"dist",
|
|
@@ -21,11 +22,10 @@
|
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/fs-extra": "^9.0.13",
|
|
24
|
-
"@types/isomorphic-fetch": "^0.0.35",
|
|
25
25
|
"fs-extra": "^11.3.0",
|
|
26
26
|
"jest": "^29.7.0",
|
|
27
27
|
"typescript": "^5.7.3",
|
|
28
|
-
"@tinacms/scripts": "1.4.
|
|
28
|
+
"@tinacms/scripts": "1.4.2"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"registry": "https://registry.npmjs.org"
|
|
@@ -34,9 +34,6 @@
|
|
|
34
34
|
"url": "https://github.com/tinacms/tinacms.git",
|
|
35
35
|
"directory": "packages/@tinacms/cli"
|
|
36
36
|
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"isomorphic-fetch": "^3.0.0"
|
|
39
|
-
},
|
|
40
37
|
"scripts": {
|
|
41
38
|
"build": "tinacms-scripts build",
|
|
42
39
|
"test": "jest --passWithNoTests",
|