1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+
1
3
import path from "path"
2
- import Configstore from "configstore"
3
- import createFetch from "@turist/fetch"
4
4
import { Store } from "./store"
5
5
import { ensureDirSync } from "fs-extra"
6
- import { isTruthy } from "gatsby-core-utils"
7
- import { InMemoryConfigStore } from "./in-memory-store"
8
6
9
- const fetch = createFetch ( )
7
+ import { InMemoryConfigStore } from "./in-memory-store"
10
8
11
9
/* The events data collection is a spooled process that
12
10
* buffers events to a local fs based buffer
@@ -15,20 +13,15 @@ const fetch = createFetch()
15
13
* to continue even when working offline.
16
14
*/
17
15
export class EventStorage {
18
- analyticsApi =
19
- process . env . GATSBY_TELEMETRY_API || `https://analytics.gatsbyjs.com/events`
20
- config : Configstore | InMemoryConfigStore
16
+ analyticsApi = process . env . GATSBY_TELEMETRY_API
17
+ config : InMemoryConfigStore
21
18
store : Store
22
19
verbose : boolean
23
20
debugEvents : boolean
24
21
disabled : boolean
25
22
26
23
constructor ( ) {
27
- try {
28
- this . config = new Configstore ( `gatsby` , { } , { globalConfigPath : true } )
29
- } catch ( e ) {
30
- this . config = new InMemoryConfigStore ( )
31
- }
24
+ this . config = new InMemoryConfigStore ( )
32
25
33
26
const baseDir = path . dirname ( this . config . path )
34
27
@@ -39,59 +32,23 @@ export class EventStorage {
39
32
}
40
33
41
34
this . store = new Store ( baseDir )
42
- this . verbose = isTruthy ( process . env . GATSBY_TELEMETRY_VERBOSE )
43
- this . debugEvents = isTruthy ( process . env . GATSBY_TELEMETRY_DEBUG )
44
- this . disabled = isTruthy ( process . env . GATSBY_TELEMETRY_DISABLED )
35
+ this . verbose = false
36
+ this . debugEvents = false
37
+ this . disabled = true
45
38
}
46
39
47
40
isTrackingDisabled ( ) : boolean {
48
41
return this . disabled
49
42
}
50
43
51
- addEvent ( event : unknown ) : void {
52
- if ( this . disabled ) {
53
- return
54
- }
55
-
56
- const eventString = JSON . stringify ( event )
57
-
58
- if ( this . debugEvents || this . verbose ) {
59
- console . log ( `Captured event:` , JSON . parse ( eventString ) )
60
-
61
- if ( this . debugEvents ) {
62
- // Bail because we don't want to send debug events
63
- return
64
- }
65
- }
66
-
67
- this . store . appendToBuffer ( eventString + `\n` )
68
- }
44
+ addEvent ( _event : unknown ) : void { }
69
45
70
46
async sendEvents ( ) : Promise < boolean > {
71
- return this . store . startFlushEvents ( async ( eventsData : string ) => {
72
- const events = eventsData
73
- . split ( `\n` )
74
- . filter ( e => e && e . length > 2 ) // drop empty lines
75
- . map ( e => JSON . parse ( e ) )
76
-
77
- return this . submitEvents ( events )
78
- } )
47
+ return true
79
48
}
80
49
81
- async submitEvents ( events : unknown ) : Promise < boolean > {
82
- try {
83
- const res = await fetch ( this . analyticsApi , {
84
- method : `POST` ,
85
- headers : {
86
- "content-type" : `application/json` ,
87
- "user-agent" : this . getUserAgent ( ) ,
88
- } ,
89
- body : JSON . stringify ( events ) ,
90
- } )
91
- return res . ok
92
- } catch ( e ) {
93
- return false
94
- }
50
+ async submitEvents ( _events : unknown ) : Promise < boolean > {
51
+ return true
95
52
}
96
53
97
54
getUserAgent ( ) : string {
@@ -103,11 +60,11 @@ export class EventStorage {
103
60
}
104
61
}
105
62
106
- getConfig ( key : string ) : string | boolean | Record < string , unknown > {
63
+ getConfig ( key : string ) : string | boolean | unknown | Record < string , unknown > {
107
64
if ( key ) {
108
65
return this . config . get ( key )
109
66
}
110
- return this . config . all
67
+ return this . config . all ( )
111
68
}
112
69
113
70
updateConfig ( key : string , value : string | number | boolean | null ) : void {
0 commit comments