@tinacms/metrics 0.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.
@@ -0,0 +1,14 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export * from './telemetry';
14
+ export * from './interfaces';
package/dist/index.js ADDED
@@ -0,0 +1,150 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ __markAsModule(target);
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __reExport = (target, module2, desc) => {
14
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
15
+ for (let key of __getOwnPropNames(module2))
16
+ if (!__hasOwnProp.call(target, key) && key !== "default")
17
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
18
+ }
19
+ return target;
20
+ };
21
+ var __toModule = (module2) => {
22
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
23
+ };
24
+
25
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/metrics/src/index.ts
26
+ __export(exports, {
27
+ Telemetry: () => Telemetry
28
+ });
29
+
30
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/metrics/src/telemetry/telemetry.ts
31
+ var import_crypto = __toModule(require("crypto"));
32
+
33
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/metrics/src/telemetry/getId.ts
34
+ var import_child_process = __toModule(require("child_process"));
35
+ function _getProjectIdByGit() {
36
+ try {
37
+ const originBuffer = (0, import_child_process.execSync)(`git config --local --get remote.origin.url`, {
38
+ timeout: 1e3,
39
+ stdio: `pipe`
40
+ });
41
+ return String(originBuffer).trim();
42
+ } catch (_) {
43
+ return null;
44
+ }
45
+ }
46
+ function getID() {
47
+ return _getProjectIdByGit() || process.env.REPOSITORY_URL || process.cwd();
48
+ }
49
+
50
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/metrics/src/telemetry/telemetry.ts
51
+ var import_isomorphic_fetch = __toModule(require("isomorphic-fetch"));
52
+
53
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/metrics/src/telemetry/getVersion.ts
54
+ var import_fs_extra = __toModule(require("fs-extra"));
55
+ var import_child_process2 = __toModule(require("child_process"));
56
+ var import_path = __toModule(require("path"));
57
+ function _executeCommand(cmd) {
58
+ try {
59
+ const originBuffer = (0, import_child_process2.execSync)(cmd, {
60
+ timeout: 1e3,
61
+ stdio: `pipe`
62
+ });
63
+ return String(originBuffer).trim();
64
+ } catch (_) {
65
+ return null;
66
+ }
67
+ }
68
+ var _getPack = (rootDir) => {
69
+ let pack = {};
70
+ try {
71
+ const rawJSON = (0, import_fs_extra.readFileSync)((0, import_path.join)(rootDir, "package.json")).toString();
72
+ pack = JSON.parse(rawJSON);
73
+ } catch (_e) {
74
+ }
75
+ return pack;
76
+ };
77
+ var getTinaVersion = () => {
78
+ var _a;
79
+ const pack = _getPack(process.cwd());
80
+ const version = (_a = pack == null ? void 0 : pack.dependencies) == null ? void 0 : _a.tinacms;
81
+ return version || "";
82
+ };
83
+ var getTinaCliVersion = () => {
84
+ var _a, _b;
85
+ const pack = _getPack(process.cwd());
86
+ const version = ((_a = pack == null ? void 0 : pack.devDependencies) == null ? void 0 : _a["@tinacms/cli"]) || ((_b = pack == null ? void 0 : pack.dependencies) == null ? void 0 : _b["@tinacms/cli"]);
87
+ return version || "";
88
+ };
89
+ var getYarnVersion = () => {
90
+ return _executeCommand("yarn -v") || "";
91
+ };
92
+ var getNpmVersion = () => {
93
+ return _executeCommand("npm -v") || "";
94
+ };
95
+
96
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/metrics/src/telemetry/telemetry.ts
97
+ var TINA_METRICS_ENDPOINT = "https://metrics.tina.io/record";
98
+ var Telemetry = class {
99
+ constructor({ disabled }) {
100
+ this.oneWayHash = (payload) => {
101
+ const hash = (0, import_crypto.createHash)("sha256");
102
+ hash.update(payload);
103
+ return hash.digest("hex");
104
+ };
105
+ this.submitRecord = async ({ event }) => {
106
+ if (this.isDisabled) {
107
+ return;
108
+ }
109
+ try {
110
+ const id = this.projectId;
111
+ const body = {
112
+ partitionKey: id,
113
+ data: {
114
+ anonymousId: id,
115
+ event: event.name,
116
+ properties: {
117
+ event,
118
+ system: {
119
+ nodeVersion: process.version,
120
+ tinaCliVersion: getTinaCliVersion(),
121
+ tinaVersion: getTinaVersion(),
122
+ yarnVersion: getYarnVersion(),
123
+ npmVersion: getNpmVersion(),
124
+ CI: Boolean(process.env.CI)
125
+ }
126
+ }
127
+ }
128
+ };
129
+ await (0, import_isomorphic_fetch.default)(TINA_METRICS_ENDPOINT, {
130
+ method: "POST",
131
+ body: JSON.stringify(body),
132
+ headers: { "content-type": "application/json" }
133
+ });
134
+ } catch (_e) {
135
+ }
136
+ };
137
+ this.projectIDRaw = getID();
138
+ this._disabled = Boolean(disabled);
139
+ }
140
+ get projectId() {
141
+ return this.oneWayHash(this.projectIDRaw);
142
+ }
143
+ get isDisabled() {
144
+ return this._disabled;
145
+ }
146
+ };
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ Telemetry
150
+ });
@@ -0,0 +1,55 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ interface EventsBase {
14
+ name: string;
15
+ }
16
+ export interface CreateTinaAppInvoke extends EventsBase {
17
+ name: 'create-tina-app:invoke';
18
+ example: string;
19
+ useYarn: boolean;
20
+ }
21
+ export interface TinaCMSAuditInvoke extends EventsBase {
22
+ name: 'tinacms:cli:audit:invoke';
23
+ clean: boolean;
24
+ useDefaults: boolean;
25
+ }
26
+ export interface TinaCMSInitInvoke extends EventsBase {
27
+ name: 'tinacms:cli:init:invoke';
28
+ }
29
+ export interface TinaCMSServerStartInvoke extends EventsBase {
30
+ name: 'tinacms:cli:server:start:invoke';
31
+ }
32
+ export interface TinaCMSServerError extends EventsBase {
33
+ name: 'tinacms:cli:server:error';
34
+ errorMessage: string;
35
+ }
36
+ export declare type Events = CreateTinaAppInvoke | TinaCMSAuditInvoke | TinaCMSInitInvoke | TinaCMSServerStartInvoke | TinaCMSServerError;
37
+ export interface MetricPayload {
38
+ partitionKey: string;
39
+ data: {
40
+ anonymousId: string;
41
+ event: Events['name'];
42
+ properties: {
43
+ event: Events;
44
+ system: {
45
+ nodeVersion: string;
46
+ tinaCliVersion: string;
47
+ tinaVersion: string;
48
+ yarnVersion: string;
49
+ npmVersion: string;
50
+ CI: boolean;
51
+ };
52
+ };
53
+ };
54
+ }
55
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export declare function getID(): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export declare const getTinaVersion: () => any;
14
+ export declare const getTinaCliVersion: () => any;
15
+ export declare const getYarnVersion: () => string;
16
+ export declare const getNpmVersion: () => string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export * from './telemetry';
@@ -0,0 +1,26 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import { Events } from '../interfaces';
14
+ export declare class Telemetry {
15
+ private projectIDRaw;
16
+ private _disabled;
17
+ constructor({ disabled }: {
18
+ disabled: any;
19
+ });
20
+ private oneWayHash;
21
+ private get projectId();
22
+ private get isDisabled();
23
+ submitRecord: ({ event }: {
24
+ event: Events;
25
+ }) => Promise<void>;
26
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@tinacms/metrics",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "typings": "dist/index.d.ts",
6
+ "files": [
7
+ "dist",
8
+ ".env"
9
+ ],
10
+ "license": "Apache-2.0",
11
+ "buildConfig": {
12
+ "entryPoints": [
13
+ {
14
+ "name": "src/index.ts",
15
+ "target": "node"
16
+ }
17
+ ]
18
+ },
19
+ "peerDependencies": {
20
+ "fs-extra": "^9.0.1"
21
+ },
22
+ "devDependencies": {
23
+ "@tinacms/scripts": "0.50.5",
24
+ "@types/fs-extra": "^9.0.11",
25
+ "@types/isomorphic-fetch": "^0.0.35",
26
+ "fs-extra": "^9.0.1",
27
+ "jest": "^27.0.6",
28
+ "typescript": "^4.3.5"
29
+ },
30
+ "scripts": {
31
+ "build": "echo \"Run `yarn build` from the root of the repository instead\"",
32
+ "test": "jest --passWithNoTests",
33
+ "types": "yarn tsc",
34
+ "test-watch": "jest --passWithNoTests --watch",
35
+ "generate:schema": "yarn node scripts/generateSchema.js"
36
+ },
37
+ "publishConfig": {
38
+ "registry": "https://registry.npmjs.org"
39
+ },
40
+ "repository": {
41
+ "url": "https://github.com/tinacms/tinacms.git",
42
+ "directory": "packages/@tinacms/cli"
43
+ },
44
+ "dependencies": {
45
+ "isomorphic-fetch": "^3.0.0"
46
+ }
47
+ }