@acmekit/telemetry 2.13.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.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/postinstall.d.ts +2 -0
- package/dist/postinstall.d.ts.map +1 -0
- package/dist/postinstall.js +15 -0
- package/dist/store.d.ts +16 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +52 -0
- package/dist/telemeter.d.ts +51 -0
- package/dist/telemeter.d.ts.map +1 -0
- package/dist/telemeter.js +157 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/util/create-flush.d.ts +3 -0
- package/dist/util/create-flush.d.ts.map +1 -0
- package/dist/util/create-flush.js +26 -0
- package/dist/util/get-term-program.d.ts +3 -0
- package/dist/util/get-term-program.d.ts.map +1 -0
- package/dist/util/get-term-program.js +14 -0
- package/dist/util/in-memory-config.d.ts +16 -0
- package/dist/util/in-memory-config.d.ts.map +1 -0
- package/dist/util/in-memory-config.js +44 -0
- package/dist/util/is-ci.d.ts +11 -0
- package/dist/util/is-ci.d.ts.map +1 -0
- package/dist/util/is-ci.js +85 -0
- package/dist/util/is-truthy.d.ts +3 -0
- package/dist/util/is-truthy.d.ts.map +1 -0
- package/dist/util/is-truthy.js +26 -0
- package/dist/util/outbox-store.d.ts +13 -0
- package/dist/util/outbox-store.d.ts.map +1 -0
- package/dist/util/outbox-store.js +109 -0
- package/dist/util/send.d.ts +2 -0
- package/dist/util/send.d.ts.map +1 -0
- package/dist/util/send.js +13 -0
- package/dist/util/show-notification.d.ts +10 -0
- package/dist/util/show-notification.d.ts.map +1 -0
- package/dist/util/show-notification.js +22 -0
- package/dist/util/telemetry-dispatcher.d.ts +16 -0
- package/dist/util/telemetry-dispatcher.d.ts.map +1 -0
- package/dist/util/telemetry-dispatcher.js +99 -0
- package/package.json +43 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function trackFeatureFlag(flag: any): void;
|
|
2
|
+
export function trackInstallation(installation: any, type: any): void;
|
|
3
|
+
export const flush: (() => Promise<void>) | undefined;
|
|
4
|
+
export function track(event: any, data?: {}): void;
|
|
5
|
+
export function setTelemetryEnabled(enabled?: boolean): void;
|
|
6
|
+
export { default as Store } from "./store";
|
|
7
|
+
export { default as Telemeter } from "./telemeter";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAmBA,kDAEC;AAED,sEASC;AA3BD,sDAA+D;AAMxD,mDAEN;AAEM,6DAEN"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Telemeter = exports.Store = exports.setTelemetryEnabled = exports.track = exports.flush = void 0;
|
|
7
|
+
exports.trackFeatureFlag = trackFeatureFlag;
|
|
8
|
+
exports.trackInstallation = trackInstallation;
|
|
9
|
+
const telemeter_1 = __importDefault(require("./telemeter"));
|
|
10
|
+
const create_flush_1 = __importDefault(require("./util/create-flush"));
|
|
11
|
+
const telemeter = new telemeter_1.default();
|
|
12
|
+
exports.flush = (0, create_flush_1.default)(telemeter.isTrackingEnabled());
|
|
13
|
+
if (exports.flush) {
|
|
14
|
+
process.on(`exit`, exports.flush);
|
|
15
|
+
}
|
|
16
|
+
const track = (event, data = {}) => {
|
|
17
|
+
telemeter.track(event, data);
|
|
18
|
+
};
|
|
19
|
+
exports.track = track;
|
|
20
|
+
const setTelemetryEnabled = (enabled = true) => {
|
|
21
|
+
telemeter.setTelemetryEnabled(enabled);
|
|
22
|
+
};
|
|
23
|
+
exports.setTelemetryEnabled = setTelemetryEnabled;
|
|
24
|
+
function trackFeatureFlag(flag) {
|
|
25
|
+
telemeter.trackFeatureFlag(flag);
|
|
26
|
+
}
|
|
27
|
+
function trackInstallation(installation, type) {
|
|
28
|
+
switch (type) {
|
|
29
|
+
case `plugin`:
|
|
30
|
+
telemeter.trackPlugin(installation);
|
|
31
|
+
break;
|
|
32
|
+
case `module`:
|
|
33
|
+
telemeter.trackModule(installation);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
var store_1 = require("./store");
|
|
38
|
+
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return __importDefault(store_1).default; } });
|
|
39
|
+
var telemeter_2 = require("./telemeter");
|
|
40
|
+
Object.defineProperty(exports, "Telemeter", { enumerable: true, get: function () { return __importDefault(telemeter_2).default; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall.d.ts","sourceRoot":"","sources":["../src/postinstall.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { isCI } = require("./util/is-ci");
|
|
3
|
+
try {
|
|
4
|
+
const showAnalyticsNotification = require(`./util/show-notification`);
|
|
5
|
+
const Store = require(`./store`);
|
|
6
|
+
const eventStorage = new Store();
|
|
7
|
+
const disabled = eventStorage.disabled_;
|
|
8
|
+
const enabledInConfig = eventStorage.getConfig(`telemetry.enabled`);
|
|
9
|
+
if (enabledInConfig === undefined && !disabled && !isCI()) {
|
|
10
|
+
showAnalyticsNotification();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
// ignore
|
|
15
|
+
}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default Store;
|
|
2
|
+
declare class Store {
|
|
3
|
+
config_: InMemoryConfigStore | Configstore;
|
|
4
|
+
outbox_: OutboxStore;
|
|
5
|
+
disabled_: boolean;
|
|
6
|
+
getQueueSize(): number;
|
|
7
|
+
getQueueCount(): number;
|
|
8
|
+
addEvent(event: any): void;
|
|
9
|
+
flushEvents(handler: any): Promise<boolean>;
|
|
10
|
+
getConfig(path: any): any;
|
|
11
|
+
setConfig(path: any, val: any): void;
|
|
12
|
+
}
|
|
13
|
+
import { InMemoryConfigStore } from "./util/in-memory-config";
|
|
14
|
+
import Configstore from "configstore";
|
|
15
|
+
import OutboxStore from "./util/outbox-store";
|
|
16
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.js"],"names":[],"mappings":";AAOA;IAGM,2CAAyE;IAM3E,qBAAuC;IAEvC,mBAA+D;IAGjE,uBAEC;IAED,wBAEC;IAED,2BAOC;IAED,4CASC;IAED,0BAEC;IAED,qCAEC;CACF;oCArDmC,yBAAyB;wBAHrC,aAAa;wBAKb,qBAAqB"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const configstore_1 = __importDefault(require("configstore"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const in_memory_config_1 = require("./util/in-memory-config");
|
|
9
|
+
const is_truthy_1 = __importDefault(require("./util/is-truthy"));
|
|
10
|
+
const outbox_store_1 = __importDefault(require("./util/outbox-store"));
|
|
11
|
+
class Store {
|
|
12
|
+
constructor() {
|
|
13
|
+
try {
|
|
14
|
+
this.config_ = new configstore_1.default(`acmekit`, {}, { globalConfigPath: true });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
this.config_ = new in_memory_config_1.InMemoryConfigStore();
|
|
18
|
+
}
|
|
19
|
+
const baseDir = path_1.default.dirname(this.config_.path);
|
|
20
|
+
this.outbox_ = new outbox_store_1.default(baseDir);
|
|
21
|
+
this.disabled_ = (0, is_truthy_1.default)(process.env.MEDUSA_DISABLE_TELEMETRY);
|
|
22
|
+
}
|
|
23
|
+
getQueueSize() {
|
|
24
|
+
return this.outbox_.getSize();
|
|
25
|
+
}
|
|
26
|
+
getQueueCount() {
|
|
27
|
+
return this.outbox_.getCount();
|
|
28
|
+
}
|
|
29
|
+
addEvent(event) {
|
|
30
|
+
if (this.disabled_) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const eventString = JSON.stringify(event);
|
|
34
|
+
return this.outbox_.appendToBuffer(eventString + `\n`);
|
|
35
|
+
}
|
|
36
|
+
async flushEvents(handler) {
|
|
37
|
+
return await this.outbox_.startFlushEvents(async (eventData) => {
|
|
38
|
+
const events = eventData
|
|
39
|
+
.split(`\n`)
|
|
40
|
+
.filter((e) => e && e.length > 2)
|
|
41
|
+
.map((e) => JSON.parse(e));
|
|
42
|
+
return await handler(events);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getConfig(path) {
|
|
46
|
+
return this.config_.get(path);
|
|
47
|
+
}
|
|
48
|
+
setConfig(path, val) {
|
|
49
|
+
return this.config_.set(path, val);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = Store;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export default Telemeter;
|
|
2
|
+
declare class Telemeter {
|
|
3
|
+
constructor(options?: {});
|
|
4
|
+
store_: Store;
|
|
5
|
+
flushAt: number;
|
|
6
|
+
maxQueueSize: any;
|
|
7
|
+
flushInterval: any;
|
|
8
|
+
flushed: boolean;
|
|
9
|
+
queueSize_: number;
|
|
10
|
+
queueCount_: number;
|
|
11
|
+
featureFlags_: Set<any>;
|
|
12
|
+
modules_: Set<any>;
|
|
13
|
+
plugins_: any[];
|
|
14
|
+
getMachineId(): any;
|
|
15
|
+
machineId: any;
|
|
16
|
+
isTrackingEnabled(): any;
|
|
17
|
+
trackingEnabled: any;
|
|
18
|
+
getOsInfo(): {
|
|
19
|
+
node_version: string;
|
|
20
|
+
platform: NodeJS.Platform;
|
|
21
|
+
release: string;
|
|
22
|
+
cpus: string | undefined;
|
|
23
|
+
is_ci: boolean;
|
|
24
|
+
ci_name: any;
|
|
25
|
+
arch: string;
|
|
26
|
+
docker: boolean;
|
|
27
|
+
term_program: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
osInfo: {
|
|
30
|
+
node_version: string;
|
|
31
|
+
platform: NodeJS.Platform;
|
|
32
|
+
release: string;
|
|
33
|
+
cpus: string | undefined;
|
|
34
|
+
is_ci: boolean;
|
|
35
|
+
ci_name: any;
|
|
36
|
+
arch: string;
|
|
37
|
+
docker: boolean;
|
|
38
|
+
term_program: string | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
getAcmeKitVersion(): any;
|
|
41
|
+
getCliVersion(): any;
|
|
42
|
+
setTelemetryEnabled(enabled: any): void;
|
|
43
|
+
track(event: any, data: any): void;
|
|
44
|
+
enqueue_(type: any, data: any): void;
|
|
45
|
+
timer: NodeJS.Timeout | undefined;
|
|
46
|
+
trackFeatureFlag(flag: any): void;
|
|
47
|
+
trackModule(module: any): void;
|
|
48
|
+
trackPlugin(plugin: any): void;
|
|
49
|
+
}
|
|
50
|
+
import Store from "./store";
|
|
51
|
+
//# sourceMappingURL=telemeter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemeter.d.ts","sourceRoot":"","sources":["../src/telemeter.js"],"names":[],"mappings":";AAeA;IACE,0BAcC;IAbC,cAAyB;IAEzB,gBAAiD;IACjD,kBAAsD;IACtD,mBAAuD;IACvD,iBAAoB;IAEpB,mBAA4C;IAC5C,oBAA8C;IAE9C,wBAA8B;IAC9B,mBAAyB;IACzB,gBAAkB;IAGpB,oBAWC;IAFC,eAA0B;IAI5B,yBAeC;IAFC,qBAA8B;IAIhC;;;;;;;;;;MAkBC;IAFC;;;;;;;;;;kBAAoB;IAItB,yBAWC;IAED,qBAeC;IAED,wCAGC;IAED,mCAEC;IAED,qCAkCC;IAHK,kCAAkD;IAKxD,kCAIC;IAED,+BAIC;IAED,+BAIC;CACF;kBAxKiB,SAAS"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const is_docker_1 = __importDefault(require("is-docker"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const store_1 = __importDefault(require("./store"));
|
|
12
|
+
const create_flush_1 = __importDefault(require("./util/create-flush"));
|
|
13
|
+
const get_term_program_1 = __importDefault(require("./util/get-term-program"));
|
|
14
|
+
const is_ci_1 = require("./util/is-ci");
|
|
15
|
+
const is_truthy_1 = __importDefault(require("./util/is-truthy"));
|
|
16
|
+
const show_notification_1 = __importDefault(require("./util/show-notification"));
|
|
17
|
+
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false;
|
|
18
|
+
class Telemeter {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.store_ = new store_1.default();
|
|
21
|
+
this.flushAt = Math.max(options.flushAt, 1) || 20;
|
|
22
|
+
this.maxQueueSize = options.maxQueueSize || 1024 * 500;
|
|
23
|
+
this.flushInterval = options.flushInterval || 10 * 1000;
|
|
24
|
+
this.flushed = false;
|
|
25
|
+
this.queueSize_ = this.store_.getQueueSize();
|
|
26
|
+
this.queueCount_ = this.store_.getQueueCount();
|
|
27
|
+
this.featureFlags_ = new Set();
|
|
28
|
+
this.modules_ = new Set();
|
|
29
|
+
this.plugins_ = [];
|
|
30
|
+
}
|
|
31
|
+
getMachineId() {
|
|
32
|
+
if (this.machineId) {
|
|
33
|
+
return this.machineId;
|
|
34
|
+
}
|
|
35
|
+
let machineId = this.store_.getConfig(`telemetry.machine_id`);
|
|
36
|
+
if (typeof machineId !== `string`) {
|
|
37
|
+
machineId = (0, uuid_1.v4)();
|
|
38
|
+
this.store_.setConfig(`telemetry.machine_id`, machineId);
|
|
39
|
+
}
|
|
40
|
+
this.machineId = machineId;
|
|
41
|
+
return machineId;
|
|
42
|
+
}
|
|
43
|
+
isTrackingEnabled() {
|
|
44
|
+
// Cache the result
|
|
45
|
+
if (this.trackingEnabled !== undefined) {
|
|
46
|
+
return this.trackingEnabled;
|
|
47
|
+
}
|
|
48
|
+
let enabled = this.store_.getConfig(`telemetry.enabled`);
|
|
49
|
+
if (enabled === undefined || enabled === null) {
|
|
50
|
+
if (!(0, is_ci_1.isCI)()) {
|
|
51
|
+
(0, show_notification_1.default)();
|
|
52
|
+
}
|
|
53
|
+
enabled = true;
|
|
54
|
+
this.store_.setConfig(`telemetry.enabled`, enabled);
|
|
55
|
+
}
|
|
56
|
+
this.trackingEnabled = enabled;
|
|
57
|
+
return enabled;
|
|
58
|
+
}
|
|
59
|
+
getOsInfo() {
|
|
60
|
+
if (this.osInfo) {
|
|
61
|
+
return this.osInfo;
|
|
62
|
+
}
|
|
63
|
+
const cpus = os_1.default.cpus();
|
|
64
|
+
const osInfo = {
|
|
65
|
+
node_version: process.version,
|
|
66
|
+
platform: os_1.default.platform(),
|
|
67
|
+
release: os_1.default.release(),
|
|
68
|
+
cpus: (cpus && cpus.length > 0 && cpus[0].model) || undefined,
|
|
69
|
+
is_ci: (0, is_ci_1.isCI)(),
|
|
70
|
+
ci_name: (0, is_ci_1.getCIName)(),
|
|
71
|
+
arch: os_1.default.arch(),
|
|
72
|
+
docker: (0, is_docker_1.default)(),
|
|
73
|
+
term_program: (0, get_term_program_1.default)(),
|
|
74
|
+
};
|
|
75
|
+
this.osInfo = osInfo;
|
|
76
|
+
return osInfo;
|
|
77
|
+
}
|
|
78
|
+
getAcmeKitVersion() {
|
|
79
|
+
try {
|
|
80
|
+
const packageJson = require.resolve(`@acmekit/acmekit/package.json`);
|
|
81
|
+
const { version } = JSON.parse(fs_1.default.readFileSync(packageJson, `utf-8`));
|
|
82
|
+
return version;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
86
|
+
console.error("failed to get acmekit version", e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return `-0.0.0`;
|
|
90
|
+
}
|
|
91
|
+
getCliVersion() {
|
|
92
|
+
try {
|
|
93
|
+
const jsonfile = (0, path_1.join)(require.resolve(`@acmekit/cli`).split(`${path_1.sep}dist`).shift(), "package.json");
|
|
94
|
+
const { version } = require(jsonfile);
|
|
95
|
+
return version;
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
99
|
+
console.error("failed to get acmekit version", e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return `-0.0.0`;
|
|
103
|
+
}
|
|
104
|
+
setTelemetryEnabled(enabled) {
|
|
105
|
+
this.trackingEnabled = enabled;
|
|
106
|
+
this.store_.setConfig(`telemetry.enabled`, enabled);
|
|
107
|
+
}
|
|
108
|
+
track(event, data) {
|
|
109
|
+
return this.enqueue_(event, data);
|
|
110
|
+
}
|
|
111
|
+
enqueue_(type, data) {
|
|
112
|
+
const event = {
|
|
113
|
+
id: `te_${(0, uuid_1.v4)()}`,
|
|
114
|
+
type,
|
|
115
|
+
properties: data,
|
|
116
|
+
timestamp: new Date(),
|
|
117
|
+
machine_id: this.getMachineId(),
|
|
118
|
+
os_info: this.getOsInfo(),
|
|
119
|
+
acmekit_version: this.getAcmeKitVersion(),
|
|
120
|
+
cli_version: this.getCliVersion(),
|
|
121
|
+
feature_flags: Array.from(this.featureFlags_),
|
|
122
|
+
modules: Array.from(this.modules_),
|
|
123
|
+
plugins: this.plugins_,
|
|
124
|
+
};
|
|
125
|
+
this.store_.addEvent(event);
|
|
126
|
+
this.queueCount_ += 1;
|
|
127
|
+
this.queueSize_ += JSON.stringify(event).length;
|
|
128
|
+
const hasReachedFlushAt = this.queueCount_ >= this.flushAt;
|
|
129
|
+
const hasReachedQueueSize = this.queueSize_ >= this.maxQueueSize;
|
|
130
|
+
if (hasReachedQueueSize || hasReachedFlushAt) {
|
|
131
|
+
const flush = (0, create_flush_1.default)(this.isTrackingEnabled());
|
|
132
|
+
flush && flush();
|
|
133
|
+
}
|
|
134
|
+
if (this.flushInterval && !this.timer) {
|
|
135
|
+
const flush = (0, create_flush_1.default)(this.isTrackingEnabled());
|
|
136
|
+
if (flush) {
|
|
137
|
+
this.timer = setTimeout(flush, this.flushInterval);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
trackFeatureFlag(flag) {
|
|
142
|
+
if (flag) {
|
|
143
|
+
this.featureFlags_.add(flag);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
trackModule(module) {
|
|
147
|
+
if (module) {
|
|
148
|
+
this.modules_.add(module);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
trackPlugin(plugin) {
|
|
152
|
+
if (plugin) {
|
|
153
|
+
this.plugins_.push(plugin);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.default = Telemeter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.js","../src/postinstall.js","../src/store.js","../src/telemeter.js","../src/util/create-flush.js","../src/util/get-term-program.js","../src/util/in-memory-config.js","../src/util/is-ci.js","../src/util/is-truthy.js","../src/util/outbox-store.js","../src/util/send.js","../src/util/show-notification.js","../src/util/telemetry-dispatcher.js"],"version":"5.9.3"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-flush.d.ts","sourceRoot":"","sources":["../../src/util/create-flush.js"],"names":[],"mappings":";AAMA,8EAiBC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const is_truthy_1 = __importDefault(require("./is-truthy"));
|
|
9
|
+
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false;
|
|
10
|
+
function createFlush(enabled) {
|
|
11
|
+
if (!enabled) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return async function flush() {
|
|
15
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
16
|
+
console.log("Flushing queue...");
|
|
17
|
+
}
|
|
18
|
+
const forked = (0, child_process_1.fork)((0, path_1.join)(__dirname, `send.js`), {
|
|
19
|
+
detached: true,
|
|
20
|
+
stdio: MEDUSA_TELEMETRY_VERBOSE ? `inherit` : `ignore`,
|
|
21
|
+
execArgv: [],
|
|
22
|
+
});
|
|
23
|
+
forked.unref();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.default = createFlush;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-term-program.d.ts","sourceRoot":"","sources":["../../src/util/get-term-program.js"],"names":[],"mappings":";AAAA,sDASC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function getTermProgram() {
|
|
4
|
+
const { TERM_PROGRAM, WT_SESSION } = process.env;
|
|
5
|
+
if (TERM_PROGRAM) {
|
|
6
|
+
return TERM_PROGRAM;
|
|
7
|
+
}
|
|
8
|
+
else if (WT_SESSION) {
|
|
9
|
+
// https://github.com/microsoft/terminal/issues/1040
|
|
10
|
+
return `WindowsTerminal`;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
exports.default = getTermProgram;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class InMemoryConfigStore {
|
|
2
|
+
config: {};
|
|
3
|
+
path: string;
|
|
4
|
+
createBaseConfig(): {
|
|
5
|
+
"telemetry.enabled": boolean;
|
|
6
|
+
"telemetry.machine_id": string;
|
|
7
|
+
};
|
|
8
|
+
get(key: any): any;
|
|
9
|
+
set(key: any, value: any): void;
|
|
10
|
+
all(): {};
|
|
11
|
+
size(): number;
|
|
12
|
+
has(key: any): boolean;
|
|
13
|
+
del(key: any): void;
|
|
14
|
+
clear(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=in-memory-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-config.d.ts","sourceRoot":"","sources":["../../src/util/in-memory-config.js"],"names":[],"mappings":"AAIA;IACE,WAAW;IACX,aAAmC;IAMnC;;;MAKC;IAED,mBAEC;IAED,gCAEC;IAED,UAEC;IAED,eAEC;IAED,uBAEC;IAED,oBAEC;IAED,cAEC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InMemoryConfigStore = void 0;
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
class InMemoryConfigStore {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.config = {};
|
|
13
|
+
this.path = (0, path_1.join)(os_1.default.tmpdir(), `acmekit`);
|
|
14
|
+
this.config = this.createBaseConfig();
|
|
15
|
+
}
|
|
16
|
+
createBaseConfig() {
|
|
17
|
+
return {
|
|
18
|
+
"telemetry.enabled": true,
|
|
19
|
+
"telemetry.machine_id": `not-a-machine-id-${(0, uuid_1.v4)()}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
get(key) {
|
|
23
|
+
return this.config[key];
|
|
24
|
+
}
|
|
25
|
+
set(key, value) {
|
|
26
|
+
this.config[key] = value;
|
|
27
|
+
}
|
|
28
|
+
all() {
|
|
29
|
+
return this.config;
|
|
30
|
+
}
|
|
31
|
+
size() {
|
|
32
|
+
return Object.keys(this.config).length;
|
|
33
|
+
}
|
|
34
|
+
has(key) {
|
|
35
|
+
return !!this.config[key];
|
|
36
|
+
}
|
|
37
|
+
del(key) {
|
|
38
|
+
delete this.config[key];
|
|
39
|
+
}
|
|
40
|
+
clear() {
|
|
41
|
+
this.config = this.createBaseConfig();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.InMemoryConfigStore = InMemoryConfigStore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines whether the environment where the code is running is in CI
|
|
3
|
+
* @return true if the environment is in CI, false otherwise
|
|
4
|
+
*/
|
|
5
|
+
export function isCI(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the name of the CI environment (e.g. "Vercel", "Heroku", etc.)
|
|
8
|
+
* @return The name of the CI if available. Defaults to null if not in CI
|
|
9
|
+
*/
|
|
10
|
+
export function getCIName(): any;
|
|
11
|
+
//# sourceMappingURL=is-ci.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-ci.d.ts","sourceRoot":"","sources":["../../src/util/is-ci.js"],"names":[],"mappings":"AAiCA;;;GAGG;AAEH,gCAEC;AAED;;;GAGG;AAEH,iCAKC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isCI = isCI;
|
|
7
|
+
exports.getCIName = getCIName;
|
|
8
|
+
const ci_info_1 = __importDefault(require("ci-info"));
|
|
9
|
+
const CI_DEFINITIONS = [
|
|
10
|
+
getEnvDetect({ key: `NOW_BUILDER_ANNOTATE`, name: `ZEIT Now` }),
|
|
11
|
+
getEnvDetect({ key: `NOW_REGION`, name: `ZEIT Now v1` }),
|
|
12
|
+
getEnvDetect({ key: `VERCEL_URL`, name: `Vercel Now` }),
|
|
13
|
+
getEnvDetect({ key: `NOW_BUILDER`, name: `Vercel Now` }),
|
|
14
|
+
getEnvDetect({ key: `VERCEL_BUILDER`, name: `Vercel Now` }),
|
|
15
|
+
getEnvDetect({ key: `CODESANDBOX_SSE`, name: `CodeSandbox` }),
|
|
16
|
+
getEnvDetect({ key: `GITHUB_ACTIONS`, name: `GitHub Actions` }),
|
|
17
|
+
getEnvDetect({ key: `CIRCLE_BRANCH`, name: `CircleCI` }),
|
|
18
|
+
getEnvDetect({ key: `CIRCLECI`, name: `CircleCI` }),
|
|
19
|
+
envFromCIAndCIName,
|
|
20
|
+
herokuDetect,
|
|
21
|
+
getEnvFromCIInfo,
|
|
22
|
+
envFromCIWithNoName,
|
|
23
|
+
];
|
|
24
|
+
function lookupCI() {
|
|
25
|
+
for (const fn of CI_DEFINITIONS) {
|
|
26
|
+
try {
|
|
27
|
+
const res = fn();
|
|
28
|
+
if (res) {
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// ignore
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const CIName = lookupCI();
|
|
39
|
+
/**
|
|
40
|
+
* Determines whether the environment where the code is running is in CI
|
|
41
|
+
* @return true if the environment is in CI, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
function isCI() {
|
|
44
|
+
return !!CIName;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the name of the CI environment (e.g. "Vercel", "Heroku", etc.)
|
|
48
|
+
* @return The name of the CI if available. Defaults to null if not in CI
|
|
49
|
+
*/
|
|
50
|
+
function getCIName() {
|
|
51
|
+
if (!isCI()) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return CIName;
|
|
55
|
+
}
|
|
56
|
+
function getEnvFromCIInfo() {
|
|
57
|
+
if (ci_info_1.default.isCI)
|
|
58
|
+
return ci_info_1.default.name || `ci-info detected w/o name`;
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function getEnvDetect({ key, name }) {
|
|
62
|
+
return function () {
|
|
63
|
+
if (process.env[key]) {
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function herokuDetect() {
|
|
70
|
+
return (typeof process.env.NODE === `string` &&
|
|
71
|
+
/\.heroku\/node\/bin\/node/.test(process.env.NODE) &&
|
|
72
|
+
`Heroku`);
|
|
73
|
+
}
|
|
74
|
+
function envFromCIAndCIName() {
|
|
75
|
+
if (process.env.CI_NAME && process.env.CI) {
|
|
76
|
+
return process.env.CI_NAME;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function envFromCIWithNoName() {
|
|
81
|
+
if (process.env.CI) {
|
|
82
|
+
return `CI detected without name`;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-truthy.d.ts","sourceRoot":"","sources":["../../src/util/is-truthy.js"],"names":[],"mappings":";AAEA,+CAkBC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Returns true for `true`, true, positive numbers
|
|
4
|
+
// Returns false for `false`, false, 0, negative integers and anything else
|
|
5
|
+
function isTruthy(value) {
|
|
6
|
+
// Return if Boolean
|
|
7
|
+
if (typeof value === `boolean`)
|
|
8
|
+
return value;
|
|
9
|
+
// Return false if null or undefined
|
|
10
|
+
if (value === undefined || value === null)
|
|
11
|
+
return false;
|
|
12
|
+
// If the String is true or false
|
|
13
|
+
if (value.toLowerCase() === `true`)
|
|
14
|
+
return true;
|
|
15
|
+
if (value.toLowerCase() === `false`)
|
|
16
|
+
return false;
|
|
17
|
+
// Now check if it's a number
|
|
18
|
+
const number = parseInt(value, 10);
|
|
19
|
+
if (isNaN(number))
|
|
20
|
+
return false;
|
|
21
|
+
if (number > 0)
|
|
22
|
+
return true;
|
|
23
|
+
// Default to false
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
exports.default = isTruthy;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default Outbox;
|
|
2
|
+
declare class Outbox {
|
|
3
|
+
constructor(baseDir: any);
|
|
4
|
+
eventsJsonFileName: string;
|
|
5
|
+
bufferFilePath: string;
|
|
6
|
+
baseDir: any;
|
|
7
|
+
appendToBuffer(event: any): void;
|
|
8
|
+
getSize(): number;
|
|
9
|
+
getCount(): number;
|
|
10
|
+
flushFile(filePath: any, flushOperation: any): Promise<boolean>;
|
|
11
|
+
startFlushEvents(flushOperation: any): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=outbox-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox-store.d.ts","sourceRoot":"","sources":["../../src/util/outbox-store.js"],"names":[],"mappings":";AAeA;IACE,0BAIC;IAHC,2BAAuC;IACvC,uBAAiE;IACjE,aAAsB;IAGxB,iCAQC;IAED,kBAcC;IAED,mBAgBC;IAED,gEAkCC;IAED,wDAeC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const is_truthy_1 = __importDefault(require("./is-truthy"));
|
|
9
|
+
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false;
|
|
10
|
+
class Outbox {
|
|
11
|
+
constructor(baseDir) {
|
|
12
|
+
this.eventsJsonFileName = `events.json`;
|
|
13
|
+
this.bufferFilePath = path_1.default.join(baseDir, this.eventsJsonFileName);
|
|
14
|
+
this.baseDir = baseDir;
|
|
15
|
+
}
|
|
16
|
+
appendToBuffer(event) {
|
|
17
|
+
try {
|
|
18
|
+
(0, fs_1.appendFileSync)(this.bufferFilePath, event, `utf8`);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
22
|
+
console.error("Failed to append to buffer", e);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getSize() {
|
|
27
|
+
if (!(0, fs_1.existsSync)(this.bufferFilePath)) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const stats = (0, fs_1.statSync)(this.bufferFilePath);
|
|
32
|
+
return stats.size;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
36
|
+
console.error("Failed to get outbox size", e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
getCount() {
|
|
42
|
+
if (!(0, fs_1.existsSync)(this.bufferFilePath)) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const fileBuffer = (0, fs_1.readFileSync)(this.bufferFilePath);
|
|
47
|
+
const str = fileBuffer.toString();
|
|
48
|
+
const lines = str.split("\n");
|
|
49
|
+
return lines.length - 1;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
53
|
+
console.error("Failed to get outbox count", e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
async flushFile(filePath, flushOperation) {
|
|
59
|
+
const now = `${Date.now()}-${process.pid}`;
|
|
60
|
+
let success = false;
|
|
61
|
+
let contents = ``;
|
|
62
|
+
try {
|
|
63
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// Unique temporary file name across multiple concurrent AcmeKit instances
|
|
67
|
+
const newPath = `${this.bufferFilePath}-${now}`;
|
|
68
|
+
(0, fs_1.renameSync)(filePath, newPath);
|
|
69
|
+
contents = (0, fs_1.readFileSync)(newPath, `utf8`);
|
|
70
|
+
(0, fs_1.unlinkSync)(newPath);
|
|
71
|
+
// There is still a chance process dies while sending data and some events are lost
|
|
72
|
+
// This will be ok for now, however
|
|
73
|
+
success = await flushOperation(contents);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
77
|
+
console.error("Failed to perform file flush", e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
// if sending fails, we write the data back to the log
|
|
82
|
+
if (!success) {
|
|
83
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
84
|
+
console.error("File flush did not succeed - writing back to file", success);
|
|
85
|
+
}
|
|
86
|
+
this.appendToBuffer(contents);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
async startFlushEvents(flushOperation) {
|
|
92
|
+
try {
|
|
93
|
+
await this.flushFile(this.bufferFilePath, flushOperation);
|
|
94
|
+
const files = (0, fs_1.readdirSync)(this.baseDir);
|
|
95
|
+
const filtered = files.filter(p => p.startsWith(`events.json`));
|
|
96
|
+
for (const file of filtered) {
|
|
97
|
+
await this.flushFile(path_1.default.join(this.baseDir, file), flushOperation);
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
103
|
+
console.error("Failed to perform flush", e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.default = Outbox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/util/send.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const telemetry_dispatcher_1 = __importDefault(require("./telemetry-dispatcher"));
|
|
7
|
+
const MEDUSA_TELEMETRY_HOST = process.env.MEDUSA_TELEMETRY_HOST || "";
|
|
8
|
+
const MEDUSA_TELEMETRY_PATH = process.env.MEDUSA_TELEMETRY_PATH || "";
|
|
9
|
+
const dispatcher = new telemetry_dispatcher_1.default({
|
|
10
|
+
host: MEDUSA_TELEMETRY_HOST,
|
|
11
|
+
path: MEDUSA_TELEMETRY_PATH,
|
|
12
|
+
});
|
|
13
|
+
dispatcher.dispatch();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default showAnalyticsNotification;
|
|
2
|
+
/**
|
|
3
|
+
* Analytics notice for the end-user
|
|
4
|
+
*/
|
|
5
|
+
declare function showAnalyticsNotification(config?: {
|
|
6
|
+
padding: number;
|
|
7
|
+
borderColor: string;
|
|
8
|
+
borderStyle: string;
|
|
9
|
+
}, message?: string): void;
|
|
10
|
+
//# sourceMappingURL=show-notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show-notification.d.ts","sourceRoot":"","sources":["../../src/util/show-notification.js"],"names":[],"mappings":";AAcA;;GAEG;AACH;;;;2BAKC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const boxen_1 = __importDefault(require("boxen"));
|
|
7
|
+
const defaultConfig = {
|
|
8
|
+
padding: 1,
|
|
9
|
+
borderColor: `blue`,
|
|
10
|
+
borderStyle: `double`,
|
|
11
|
+
};
|
|
12
|
+
const defaultMessage = `AcmeKit collects anonymous usage analytics\n` +
|
|
13
|
+
`to help improve AcmeKit for all users.\n` +
|
|
14
|
+
`\n` +
|
|
15
|
+
`If you'd like to opt-out, you can use \`acmekit telemetry --disable\`\n`;
|
|
16
|
+
/**
|
|
17
|
+
* Analytics notice for the end-user
|
|
18
|
+
*/
|
|
19
|
+
function showAnalyticsNotification(config = defaultConfig, message = defaultMessage) {
|
|
20
|
+
console.log((0, boxen_1.default)(message, config));
|
|
21
|
+
}
|
|
22
|
+
exports.default = showAnalyticsNotification;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default TelemetryDispatcher;
|
|
2
|
+
declare class TelemetryDispatcher {
|
|
3
|
+
constructor(options: any);
|
|
4
|
+
store_: Store;
|
|
5
|
+
host: string;
|
|
6
|
+
path: string;
|
|
7
|
+
axiosInstance: any;
|
|
8
|
+
timeout: any;
|
|
9
|
+
flushed: boolean;
|
|
10
|
+
isTrackingEnabled(): any;
|
|
11
|
+
trackingEnabled: any;
|
|
12
|
+
dispatch(): Promise<void>;
|
|
13
|
+
isErrorRetryable_(error: any): boolean;
|
|
14
|
+
}
|
|
15
|
+
import Store from "../store";
|
|
16
|
+
//# sourceMappingURL=telemetry-dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-dispatcher.d.ts","sourceRoot":"","sources":["../../src/util/telemetry-dispatcher.js"],"names":[],"mappings":";AAUA;IACE,0BAsBC;IArBC,cAAyB;IAEzB,aAEC;IACD,aAAiD;IAMjD,mBAAkC;IAElC,aAAuC;IACvC,iBAAoB;IAStB,yBAaC;IAFC,qBAA8B;IAIhC,0BAqCC;IAED,uCAsBC;CACF;kBA3GiB,UAAU"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const remove_trailing_slash_1 = __importDefault(require("remove-trailing-slash"));
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
9
|
+
const show_notification_1 = __importDefault(require("./show-notification"));
|
|
10
|
+
const store_1 = __importDefault(require("../store"));
|
|
11
|
+
const is_truthy_1 = __importDefault(require("./is-truthy"));
|
|
12
|
+
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false;
|
|
13
|
+
class TelemetryDispatcher {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.store_ = new store_1.default();
|
|
16
|
+
this.host = (0, remove_trailing_slash_1.default)(options.host || "https://telemetry.acmekit-commerce.com");
|
|
17
|
+
this.path = (0, remove_trailing_slash_1.default)(options.path || "/batch");
|
|
18
|
+
let axiosInstance = options.axiosInstance;
|
|
19
|
+
if (!axiosInstance) {
|
|
20
|
+
axiosInstance = axios_1.default.create();
|
|
21
|
+
}
|
|
22
|
+
this.axiosInstance = axiosInstance;
|
|
23
|
+
this.timeout = options.timeout || false;
|
|
24
|
+
this.flushed = false;
|
|
25
|
+
(0, axios_retry_1.default)(this.axiosInstance, {
|
|
26
|
+
retries: 3,
|
|
27
|
+
retryDelay: axios_retry_1.default.exponentialDelay,
|
|
28
|
+
retryCondition: this.isErrorRetryable_,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
isTrackingEnabled() {
|
|
32
|
+
// Cache the result
|
|
33
|
+
if (this.trackingEnabled !== undefined) {
|
|
34
|
+
return this.trackingEnabled;
|
|
35
|
+
}
|
|
36
|
+
let enabled = this.store_.getConfig(`telemetry.enabled`);
|
|
37
|
+
if (enabled === undefined || enabled === null) {
|
|
38
|
+
(0, show_notification_1.default)();
|
|
39
|
+
enabled = true;
|
|
40
|
+
this.store_.setConfig(`telemetry.enabled`, enabled);
|
|
41
|
+
}
|
|
42
|
+
this.trackingEnabled = enabled;
|
|
43
|
+
return enabled;
|
|
44
|
+
}
|
|
45
|
+
async dispatch() {
|
|
46
|
+
if (!this.isTrackingEnabled()) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await this.store_.flushEvents(async (events) => {
|
|
50
|
+
if (!events.length) {
|
|
51
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
52
|
+
console.log("No events to POST - skipping");
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const data = {
|
|
57
|
+
batch: events,
|
|
58
|
+
timestamp: new Date(),
|
|
59
|
+
};
|
|
60
|
+
const req = {
|
|
61
|
+
headers: {},
|
|
62
|
+
};
|
|
63
|
+
return await this.axiosInstance
|
|
64
|
+
.post(`${this.host}${this.path}`, data, req)
|
|
65
|
+
.then(() => {
|
|
66
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
67
|
+
console.log("POSTing batch succeeded");
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
})
|
|
71
|
+
.catch(e => {
|
|
72
|
+
if ((0, is_truthy_1.default)(MEDUSA_TELEMETRY_VERBOSE)) {
|
|
73
|
+
console.error("Failed to POST event batch", e);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
isErrorRetryable_(error) {
|
|
80
|
+
// Retry Network Errors.
|
|
81
|
+
if (axios_retry_1.default.isNetworkError(error)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (!error.response) {
|
|
85
|
+
// Cannot determine if the request can be retried
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
// Retry Server Errors (5xx).
|
|
89
|
+
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
// Retry if rate limited.
|
|
93
|
+
if (error.response.status === 429) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.default = TelemetryDispatcher;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acmekit/telemetry",
|
|
3
|
+
"version": "2.13.1",
|
|
4
|
+
"description": "Telemetry for AcmeKit",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/acmekit/acmekit",
|
|
9
|
+
"directory": "packages/acmekit-telemetry"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"author": "Sebastian Rindom",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "nodemon --watch plugins/ --watch src/ --exec node src/index.js",
|
|
24
|
+
"prepare": "cross-env NODE_ENV=production yarn run build",
|
|
25
|
+
"watch": "yarn run -T tsc --build --watch",
|
|
26
|
+
"build": "yarn run -T rimraf dist && yarn run -T tsc --build",
|
|
27
|
+
"serve": "node dist/index.js",
|
|
28
|
+
"postinstall": "node dist/postinstall.js || true",
|
|
29
|
+
"test": "../../node_modules/.bin/jest --passWithNoTests src"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@babel/runtime": "^7.26.10",
|
|
33
|
+
"axios": "^1.13.1",
|
|
34
|
+
"axios-retry": "^3.1.9",
|
|
35
|
+
"boxen": "^5.0.1",
|
|
36
|
+
"ci-info": "^3.2.0",
|
|
37
|
+
"configstore": "^5.0.1",
|
|
38
|
+
"is-docker": "^2.2.1",
|
|
39
|
+
"remove-trailing-slash": "^0.1.1",
|
|
40
|
+
"uuid": "^9.0.0"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "41a5425405aea5045a26def95c0dc00cf4a5a44d"
|
|
43
|
+
}
|