@webiny/telemetry 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f

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/cli.js CHANGED
@@ -1,18 +1,29 @@
1
- const baseSendEvent = require("./sendEvent");
1
+ const createSendEvent = require("./sendEvent");
2
2
  const { globalConfig } = require("@webiny/global-config");
3
3
 
4
4
  const sendEvent = ({ event, user, version, properties, extraPayload }) => {
5
- if (!isEnabled()) {
6
- return;
5
+ const shouldSend = isEnabled();
6
+
7
+ try {
8
+ const sendTelemetry = createSendEvent({
9
+ event,
10
+ user: user || globalConfig.get("id"),
11
+ version: version || require("./package.json").version,
12
+ properties,
13
+ extraPayload
14
+ });
15
+
16
+ if (shouldSend) {
17
+ return sendTelemetry();
18
+ }
19
+ } catch (err) {
20
+ // Ignore errors if telemetry is disabled.
21
+ if (!shouldSend) {
22
+ return;
23
+ }
24
+
25
+ throw err;
7
26
  }
8
-
9
- return baseSendEvent({
10
- event,
11
- user: user || globalConfig.get("id"),
12
- version: version || require("./package.json").version,
13
- properties,
14
- extraPayload
15
- });
16
27
  };
17
28
 
18
29
  const enable = () => {
@@ -30,6 +41,7 @@ const isEnabled = () => {
30
41
  return false;
31
42
  }
32
43
 
44
+ // `tracking` is left here for backwards compatibility with previous versions of Webiny.
33
45
  return config.tracking !== false;
34
46
  };
35
47
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@webiny/telemetry",
3
- "version": "0.0.0-mt-2",
3
+ "version": "0.0.0-unstable.085ff6572f",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@webiny/global-config": "0.0.0-mt-2",
6
+ "@webiny/global-config": "0.0.0-unstable.085ff6572f",
7
7
  "form-data": "3.0.0",
8
8
  "node-fetch": "2.6.1"
9
9
  },
@@ -11,5 +11,5 @@
11
11
  "access": "public",
12
12
  "directory": "."
13
13
  },
14
- "gitHead": "3c0dcfb3c22c9f83107fdb97b25014cd03d9db7d"
14
+ "gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
15
15
  }
package/react.js CHANGED
@@ -1,14 +1,15 @@
1
- const baseSendEvent = require("./sendEvent");
1
+ const createSendEvent = require("./sendEvent");
2
2
 
3
3
  const setProperties = data => {
4
4
  return sendEvent("$identify", data);
5
5
  };
6
-
6
+ /**
7
+ *
8
+ * @param event {String}
9
+ * @param data {Record<string, string>}
10
+ * @return {Promise<T>}
11
+ */
7
12
  const sendEvent = (event, data = {}) => {
8
- if (process.env.REACT_APP_WEBINY_TELEMETRY === "false") {
9
- return;
10
- }
11
-
12
13
  let properties = {};
13
14
  let extraPayload = {};
14
15
  if (event !== "$identify") {
@@ -19,13 +20,17 @@ const sendEvent = (event, data = {}) => {
19
20
  };
20
21
  }
21
22
 
22
- return baseSendEvent({
23
+ const shouldSend = process.env.REACT_APP_WEBINY_TELEMETRY !== "false";
24
+
25
+ const sendTelemetry = createSendEvent({
23
26
  event,
24
27
  properties,
25
28
  extraPayload,
26
29
  user: process.env.REACT_APP_USER_ID,
27
30
  version: process.env.REACT_APP_WEBINY_VERSION
28
31
  });
32
+
33
+ return shouldSend ? sendTelemetry() : Promise.resolve();
29
34
  };
30
35
 
31
36
  module.exports = { setProperties, sendEvent };
package/sendEvent.js CHANGED
@@ -6,15 +6,9 @@ const API_URL = "https://t.webiny.com";
6
6
 
7
7
  /**
8
8
  * The main `sendEvent` function.
9
- * Note: it's recommended the one from `cli.js` and `react.js` files is used instead.
10
- * @param event
11
- * @param user
12
- * @param version
13
- * @param properties
14
- * @param extraPayload
15
- * @returns {Promise<T>}
9
+ * NOTE: don't use this in your app directly. Instead, use the one from `cli.js` or `react.js` files accordingly.
16
10
  */
17
- module.exports = async ({ event, user, version, properties, extraPayload } = {}) => {
11
+ module.exports = ({ event, user, version, properties, extraPayload } = {}) => {
18
12
  if (!event) {
19
13
  throw new Error(`Cannot send event - missing "event" name.`);
20
14
  }
@@ -50,10 +44,13 @@ module.exports = async ({ event, user, version, properties, extraPayload } = {})
50
44
  const body = new FormData();
51
45
  body.append("data", Buffer.from(JSON.stringify(payload)).toString("base64"));
52
46
 
53
- return fetch(API_URL + "/capture/", {
54
- body,
55
- method: "POST"
56
- }).catch(() => {
57
- // Ignore errors
58
- });
47
+ // Return a function which will send the prepared body when invoked.
48
+ return () => {
49
+ return fetch(API_URL + "/capture/", {
50
+ body,
51
+ method: "POST"
52
+ }).catch(() => {
53
+ // Ignore errors
54
+ });
55
+ };
59
56
  };
package/CHANGELOG.md DELETED
@@ -1,466 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [5.18.1](https://github.com/webiny/webiny-js/compare/v5.18.1-beta.0...v5.18.1) (2021-11-25)
7
-
8
- **Note:** Version bump only for package @webiny/telemetry
9
-
10
-
11
-
12
-
13
-
14
- ## [5.18.1-beta.0](https://github.com/webiny/webiny-js/compare/v5.18.0...v5.18.1-beta.0) (2021-11-25)
15
-
16
- **Note:** Version bump only for package @webiny/telemetry
17
-
18
-
19
-
20
-
21
-
22
- # [5.18.0](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.4...v5.18.0) (2021-11-24)
23
-
24
- **Note:** Version bump only for package @webiny/telemetry
25
-
26
-
27
-
28
-
29
-
30
- # [5.18.0-beta.4](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.3...v5.18.0-beta.4) (2021-11-23)
31
-
32
- **Note:** Version bump only for package @webiny/telemetry
33
-
34
-
35
-
36
-
37
-
38
- # [5.18.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.2...v5.18.0-beta.3) (2021-11-22)
39
-
40
- **Note:** Version bump only for package @webiny/telemetry
41
-
42
-
43
-
44
-
45
-
46
- # [5.18.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.1...v5.18.0-beta.2) (2021-11-21)
47
-
48
- **Note:** Version bump only for package @webiny/telemetry
49
-
50
-
51
-
52
-
53
-
54
- # [5.18.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.18.0-beta.0...v5.18.0-beta.1) (2021-11-19)
55
-
56
- **Note:** Version bump only for package @webiny/telemetry
57
-
58
-
59
-
60
-
61
-
62
- # [5.18.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.4...v5.18.0-beta.0) (2021-11-19)
63
-
64
- **Note:** Version bump only for package @webiny/telemetry
65
-
66
-
67
-
68
-
69
-
70
- ## [5.17.4](https://github.com/webiny/webiny-js/compare/v5.17.4-beta.1...v5.17.4) (2021-11-19)
71
-
72
- **Note:** Version bump only for package @webiny/telemetry
73
-
74
-
75
-
76
-
77
-
78
- ## [5.17.4-beta.1](https://github.com/webiny/webiny-js/compare/v5.17.4-beta.0...v5.17.4-beta.1) (2021-11-19)
79
-
80
- **Note:** Version bump only for package @webiny/telemetry
81
-
82
-
83
-
84
-
85
-
86
- ## [5.17.4-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.3...v5.17.4-beta.0) (2021-11-19)
87
-
88
- **Note:** Version bump only for package @webiny/telemetry
89
-
90
-
91
-
92
-
93
-
94
- ## [5.17.3](https://github.com/webiny/webiny-js/compare/v5.17.3-beta.0...v5.17.3) (2021-11-15)
95
-
96
- **Note:** Version bump only for package @webiny/telemetry
97
-
98
-
99
-
100
-
101
-
102
- ## [5.17.3-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.2...v5.17.3-beta.0) (2021-11-12)
103
-
104
- **Note:** Version bump only for package @webiny/telemetry
105
-
106
-
107
-
108
-
109
-
110
- ## [5.17.2](https://github.com/webiny/webiny-js/compare/v5.17.2-beta.0...v5.17.2) (2021-11-11)
111
-
112
- **Note:** Version bump only for package @webiny/telemetry
113
-
114
-
115
-
116
-
117
-
118
- ## [5.17.2-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.1...v5.17.2-beta.0) (2021-11-11)
119
-
120
-
121
- ### Bug Fixes
122
-
123
- * force same version on all packages ([9cbae8b](https://github.com/webiny/webiny-js/commit/9cbae8b050900546eb17932c23a609593211c1c8))
124
-
125
-
126
-
127
-
128
-
129
- # [5.17.0](https://github.com/webiny/webiny-js/compare/v5.17.0-beta.2...v5.17.0) (2021-11-08)
130
-
131
- **Note:** Version bump only for package @webiny/telemetry
132
-
133
-
134
-
135
-
136
-
137
- # [5.17.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.17.0-beta.1...v5.17.0-beta.2) (2021-11-08)
138
-
139
- **Note:** Version bump only for package @webiny/telemetry
140
-
141
-
142
-
143
-
144
-
145
- # [5.17.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.16.0...v5.17.0-beta.1) (2021-11-08)
146
-
147
- **Note:** Version bump only for package @webiny/telemetry
148
-
149
-
150
-
151
-
152
-
153
- # [5.16.0](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.4...v5.16.0) (2021-10-21)
154
-
155
- **Note:** Version bump only for package @webiny/telemetry
156
-
157
-
158
-
159
-
160
-
161
- # [5.16.0-beta.4](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.3...v5.16.0-beta.4) (2021-10-20)
162
-
163
- **Note:** Version bump only for package @webiny/telemetry
164
-
165
-
166
-
167
-
168
-
169
- # [5.16.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.2...v5.16.0-beta.3) (2021-10-20)
170
-
171
- **Note:** Version bump only for package @webiny/telemetry
172
-
173
-
174
-
175
-
176
-
177
- # [5.16.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.1...v5.16.0-beta.2) (2021-10-20)
178
-
179
- **Note:** Version bump only for package @webiny/telemetry
180
-
181
-
182
-
183
-
184
-
185
- # [5.16.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.16.0-beta.0...v5.16.0-beta.1) (2021-10-19)
186
-
187
- **Note:** Version bump only for package @webiny/telemetry
188
-
189
-
190
-
191
-
192
-
193
- # [5.16.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.17.0-beta.0...v5.16.0-beta.0) (2021-10-19)
194
-
195
- **Note:** Version bump only for package @webiny/telemetry
196
-
197
-
198
-
199
-
200
-
201
- # [5.17.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.15.0...v5.17.0-beta.0) (2021-10-18)
202
-
203
- **Note:** Version bump only for package @webiny/telemetry
204
-
205
-
206
-
207
-
208
-
209
- # [5.15.0](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.3...v5.15.0) (2021-09-30)
210
-
211
- **Note:** Version bump only for package @webiny/telemetry
212
-
213
-
214
-
215
-
216
-
217
- # [5.15.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.2...v5.15.0-beta.3) (2021-09-30)
218
-
219
- **Note:** Version bump only for package @webiny/telemetry
220
-
221
-
222
-
223
-
224
-
225
- # [5.15.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.1...v5.15.0-beta.2) (2021-09-29)
226
-
227
- **Note:** Version bump only for package @webiny/telemetry
228
-
229
-
230
-
231
-
232
-
233
- # [5.15.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.15.0-beta.0...v5.15.0-beta.1) (2021-09-28)
234
-
235
- **Note:** Version bump only for package @webiny/telemetry
236
-
237
-
238
-
239
-
240
-
241
- # [5.15.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.14.0...v5.15.0-beta.0) (2021-09-16)
242
-
243
-
244
- ### Bug Fixes
245
-
246
- * add comment ([61dafeb](https://github.com/webiny/webiny-js/commit/61dafeb08883b1c80033d3164581f56138fee675))
247
- * correct args passing in `setProperties` function ([2ac0fed](https://github.com/webiny/webiny-js/commit/2ac0fedb8bf760b15686de44523138816e708c36))
248
- * correct if statements ([1dcdd73](https://github.com/webiny/webiny-js/commit/1dcdd735d89f1918952481a6ae510a60cf113b7f))
249
- * create utils ([6a24dcf](https://github.com/webiny/webiny-js/commit/6a24dcfb02130a672c1e90794910f8a0549f659d))
250
- * remove old api folder ([5dce8e2](https://github.com/webiny/webiny-js/commit/5dce8e2c7871fd1e24326e73e3a9459208ce7f75))
251
- * rename to `extraPayload` ([b5bcda8](https://github.com/webiny/webiny-js/commit/b5bcda88029c003d0c5704a37bff4771b9056d5e))
252
- * update dependencies ([37f2691](https://github.com/webiny/webiny-js/commit/37f2691f3cb615615a089d977f58a22a8bb21f50))
253
- * use base `sendEvent` function ([6f93072](https://github.com/webiny/webiny-js/commit/6f9307212e05b98f2a4866002258238b216e0b3b))
254
- * use built-in isEnabled ([4051257](https://github.com/webiny/webiny-js/commit/4051257c58165dbcc9805283d183583ed0bf7d15))
255
- * use global-config package ([a678b18](https://github.com/webiny/webiny-js/commit/a678b18d9d760a69eb6badaaf6451acd3c7fb953))
256
-
257
-
258
- ### Features
259
-
260
- * add telemetry getter ([b1a5e8d](https://github.com/webiny/webiny-js/commit/b1a5e8df96b1591266fbd8df90d6689a526da0f3))
261
- * add utils ([d9be82a](https://github.com/webiny/webiny-js/commit/d9be82a76f5210704c71cd8e191aca698cb0963c))
262
- * create `sendEvent` function for CLI environment ([d0babff](https://github.com/webiny/webiny-js/commit/d0babffeb1cb3a7a796caa8a25f3f9a2ba9359d7))
263
- * create base `sendEvent` function ([a764e85](https://github.com/webiny/webiny-js/commit/a764e854c5da0ebcb99038e9b9aaf3184202edc3))
264
-
265
-
266
-
267
-
268
-
269
- # [5.14.0](https://github.com/webiny/webiny-js/compare/v5.14.0-beta.0...v5.14.0) (2021-08-30)
270
-
271
- **Note:** Version bump only for package @webiny/telemetry
272
-
273
-
274
-
275
-
276
-
277
- # [5.14.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.13.0...v5.14.0-beta.0) (2021-08-26)
278
-
279
- **Note:** Version bump only for package @webiny/telemetry
280
-
281
-
282
-
283
-
284
-
285
- # [5.13.0](https://github.com/webiny/webiny-js/compare/v5.13.0-beta.4...v5.13.0) (2021-08-18)
286
-
287
- **Note:** Version bump only for package @webiny/telemetry
288
-
289
-
290
-
291
-
292
-
293
- # [5.13.0-beta.4](https://github.com/webiny/webiny-js/compare/v5.13.0-beta.3...v5.13.0-beta.4) (2021-08-18)
294
-
295
- **Note:** Version bump only for package @webiny/telemetry
296
-
297
-
298
-
299
-
300
-
301
- # [5.13.0-beta.3](https://github.com/webiny/webiny-js/compare/v5.13.0-beta.2...v5.13.0-beta.3) (2021-08-17)
302
-
303
- **Note:** Version bump only for package @webiny/telemetry
304
-
305
-
306
-
307
-
308
-
309
- # [5.13.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.13.0-beta.1...v5.13.0-beta.2) (2021-08-17)
310
-
311
- **Note:** Version bump only for package @webiny/telemetry
312
-
313
-
314
-
315
-
316
-
317
- # [5.13.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.13.0-beta.0...v5.13.0-beta.1) (2021-08-16)
318
-
319
- **Note:** Version bump only for package @webiny/telemetry
320
-
321
-
322
-
323
-
324
-
325
- # [5.13.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.12.0...v5.13.0-beta.0) (2021-08-16)
326
-
327
- **Note:** Version bump only for package @webiny/telemetry
328
-
329
-
330
-
331
-
332
-
333
- # [5.12.0](https://github.com/webiny/webiny-js/compare/v5.12.0-beta.1...v5.12.0) (2021-08-05)
334
-
335
- **Note:** Version bump only for package @webiny/telemetry
336
-
337
-
338
-
339
-
340
-
341
- # [5.12.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.12.0-beta.0...v5.12.0-beta.1) (2021-08-05)
342
-
343
- **Note:** Version bump only for package @webiny/telemetry
344
-
345
-
346
-
347
-
348
-
349
- # [5.12.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.11.1...v5.12.0-beta.0) (2021-08-04)
350
-
351
- **Note:** Version bump only for package @webiny/telemetry
352
-
353
-
354
-
355
-
356
-
357
- ## [5.11.1](https://github.com/webiny/webiny-js/compare/v5.11.1-beta.0...v5.11.1) (2021-07-31)
358
-
359
- **Note:** Version bump only for package @webiny/telemetry
360
-
361
-
362
-
363
-
364
-
365
- ## [5.11.1-beta.0](https://github.com/webiny/webiny-js/compare/v5.11.0...v5.11.1-beta.0) (2021-07-31)
366
-
367
- **Note:** Version bump only for package @webiny/telemetry
368
-
369
-
370
-
371
-
372
-
373
- # [5.11.0](https://github.com/webiny/webiny-js/compare/v5.11.0-beta.2...v5.11.0) (2021-07-22)
374
-
375
- **Note:** Version bump only for package @webiny/telemetry
376
-
377
-
378
-
379
-
380
-
381
- # [5.11.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.11.0-beta.1...v5.11.0-beta.2) (2021-07-21)
382
-
383
- **Note:** Version bump only for package @webiny/telemetry
384
-
385
-
386
-
387
-
388
-
389
- # [5.11.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.11.0-beta.0...v5.11.0-beta.1) (2021-07-21)
390
-
391
- **Note:** Version bump only for package @webiny/telemetry
392
-
393
-
394
-
395
-
396
-
397
- # [5.11.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.10.0...v5.11.0-beta.0) (2021-07-21)
398
-
399
- **Note:** Version bump only for package @webiny/telemetry
400
-
401
-
402
-
403
-
404
-
405
- # [5.10.0](https://github.com/webiny/webiny-js/compare/v5.10.0-beta.2...v5.10.0) (2021-07-06)
406
-
407
- **Note:** Version bump only for package @webiny/telemetry
408
-
409
-
410
-
411
-
412
-
413
- # [5.10.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.10.0-beta.1...v5.10.0-beta.2) (2021-07-06)
414
-
415
- **Note:** Version bump only for package @webiny/telemetry
416
-
417
-
418
-
419
-
420
-
421
- # [5.10.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.10.0-beta.0...v5.10.0-beta.1) (2021-07-06)
422
-
423
- **Note:** Version bump only for package @webiny/telemetry
424
-
425
-
426
-
427
-
428
-
429
- # [5.10.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.9.0...v5.10.0-beta.0) (2021-07-02)
430
-
431
- **Note:** Version bump only for package @webiny/telemetry
432
-
433
-
434
-
435
-
436
-
437
- # [5.9.0](https://github.com/webiny/webiny-js/compare/v5.9.0-beta.2...v5.9.0) (2021-06-21)
438
-
439
- **Note:** Version bump only for package @webiny/telemetry
440
-
441
-
442
-
443
-
444
-
445
- # [5.9.0-beta.2](https://github.com/webiny/webiny-js/compare/v5.9.0-beta.1...v5.9.0-beta.2) (2021-06-20)
446
-
447
- **Note:** Version bump only for package @webiny/telemetry
448
-
449
-
450
-
451
-
452
-
453
- # [5.9.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.9.0-beta.0...v5.9.0-beta.1) (2021-06-20)
454
-
455
- **Note:** Version bump only for package @webiny/telemetry
456
-
457
-
458
-
459
-
460
-
461
- # [5.9.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.8.0...v5.9.0-beta.0) (2021-06-18)
462
-
463
-
464
- ### Bug Fixes
465
-
466
- * **telemetry:** rename package and upgrade configs and env vars loading ([4791937](https://github.com/webiny/webiny-js/commit/4791937de3ec1431c82fca1dc2e91da9c7ac49d3))