@tinacms/metrics 1.1.0 → 2.0.0

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.
Files changed (2) hide show
  1. package/dist/index.js +49 -84
  2. package/package.json +3 -2
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
- var import_crypto = require("crypto");
2
+ import { createHash } from "crypto";
38
3
 
39
4
  // src/telemetry/getId.ts
40
- var import_child_process = require("child_process");
5
+ import { execSync } from "child_process";
41
6
  function _getProjectIdByGit() {
42
7
  try {
43
- const originBuffer = (0, import_child_process.execSync)(
8
+ const originBuffer = execSync(
44
9
  `git config --local --get remote.origin.url`,
45
10
  {
46
11
  timeout: 1e3,
@@ -57,15 +22,15 @@ function getID() {
57
22
  }
58
23
 
59
24
  // src/telemetry/telemetry.ts
60
- var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
25
+ import fetch from "isomorphic-fetch";
61
26
 
62
27
  // src/telemetry/getVersion.ts
63
- var import_fs_extra = require("fs-extra");
64
- var import_child_process2 = require("child_process");
65
- var import_path = require("path");
28
+ import fse from "fs-extra";
29
+ import { execSync as execSync2 } from "child_process";
30
+ import { join } from "path";
66
31
  function _executeCommand(cmd) {
67
32
  try {
68
- const originBuffer = (0, import_child_process2.execSync)(cmd, {
33
+ const originBuffer = execSync2(cmd, {
69
34
  timeout: 1e3,
70
35
  stdio: `pipe`
71
36
  });
@@ -77,9 +42,7 @@ function _executeCommand(cmd) {
77
42
  var _getPack = (rootDir) => {
78
43
  let pack = {};
79
44
  try {
80
- const rawJSON = (0, import_fs_extra.readFileSync)(
81
- (0, import_path.join)(rootDir, "package.json")
82
- ).toString();
45
+ const rawJSON = fse.readFileSync(join(rootDir, "package.json")).toString();
83
46
  pack = JSON.parse(rawJSON);
84
47
  } catch (_e) {
85
48
  }
@@ -105,54 +68,56 @@ var getNpmVersion = () => {
105
68
  // src/telemetry/telemetry.ts
106
69
  var TINA_METRICS_ENDPOINT = "https://metrics.tina.io/record";
107
70
  var Telemetry = class {
71
+ // private config: Conf<Record<string, unknown>>
72
+ projectIDRaw;
73
+ _disabled;
108
74
  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
75
  this.projectIDRaw = getID();
145
76
  const { NO_TELEMETRY } = process.env;
146
77
  this._disabled = NO_TELEMETRY === "1" || NO_TELEMETRY === "true" || Boolean(disabled);
147
78
  }
79
+ oneWayHash = (payload) => {
80
+ const hash = createHash("sha256");
81
+ hash.update(payload);
82
+ return hash.digest("hex");
83
+ };
148
84
  get projectId() {
149
85
  return this.oneWayHash(this.projectIDRaw);
150
86
  }
151
87
  get isDisabled() {
152
88
  return this._disabled;
153
89
  }
90
+ submitRecord = async ({ event }) => {
91
+ if (this.isDisabled) {
92
+ return;
93
+ }
94
+ try {
95
+ const id = this.projectId;
96
+ const body = {
97
+ partitionKey: id,
98
+ data: {
99
+ anonymousId: id,
100
+ event: event.name,
101
+ properties: {
102
+ ...event,
103
+ nodeVersion: process.version,
104
+ tinaCliVersion: getTinaCliVersion(),
105
+ tinaVersion: getTinaVersion(),
106
+ yarnVersion: getYarnVersion(),
107
+ npmVersion: getNpmVersion(),
108
+ CI: Boolean(process.env.CI)
109
+ }
110
+ }
111
+ };
112
+ await fetch(TINA_METRICS_ENDPOINT, {
113
+ method: "POST",
114
+ body: JSON.stringify(body),
115
+ headers: { "content-type": "application/json" }
116
+ });
117
+ } catch (_e) {
118
+ }
119
+ };
154
120
  };
155
- // Annotate the CommonJS export names for ESM import in node:
156
- 0 && (module.exports = {
121
+ export {
157
122
  Telemetry
158
- });
123
+ };
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@tinacms/metrics",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
+ "type": "module",
5
6
  "typings": "dist/index.d.ts",
6
7
  "files": [
7
8
  "dist",
@@ -25,7 +26,7 @@
25
26
  "fs-extra": "^11.3.0",
26
27
  "jest": "^29.7.0",
27
28
  "typescript": "^5.7.3",
28
- "@tinacms/scripts": "1.4.0"
29
+ "@tinacms/scripts": "1.4.1"
29
30
  },
30
31
  "publishConfig": {
31
32
  "registry": "https://registry.npmjs.org"