@learnpack/learnpack 4.0.10 → 4.0.13
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +16 -20
- package/lib/commands/audit.d.ts +6 -6
- package/lib/commands/audit.js +327 -327
- package/lib/commands/clean.d.ts +8 -8
- package/lib/commands/clean.js +22 -22
- package/lib/commands/download.d.ts +13 -13
- package/lib/commands/download.js +52 -52
- package/lib/commands/init.d.ts +9 -9
- package/lib/commands/init.js +127 -127
- package/lib/commands/login.d.ts +14 -14
- package/lib/commands/login.js +34 -34
- package/lib/commands/logout.d.ts +14 -14
- package/lib/commands/logout.js +34 -34
- package/lib/commands/publish.d.ts +11 -14
- package/lib/commands/publish.js +160 -82
- package/lib/commands/start.d.ts +7 -7
- package/lib/commands/start.js +252 -250
- package/lib/commands/test.d.ts +6 -6
- package/lib/commands/test.js +62 -62
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -4
- package/lib/managers/config/allowed_files.d.ts +5 -5
- package/lib/managers/config/allowed_files.js +30 -30
- package/lib/managers/config/defaults.d.ts +47 -48
- package/lib/managers/config/defaults.js +51 -51
- package/lib/managers/config/exercise.d.ts +36 -36
- package/lib/managers/config/exercise.js +243 -236
- package/lib/managers/config/index.d.ts +3 -3
- package/lib/managers/config/index.js +464 -459
- package/lib/managers/file.d.ts +14 -14
- package/lib/managers/file.js +190 -184
- package/lib/managers/gitpod.d.ts +3 -3
- package/lib/managers/gitpod.js +67 -67
- package/lib/managers/server/index.d.ts +5 -6
- package/lib/managers/server/index.js +58 -58
- package/lib/managers/server/routes.d.ts +4 -4
- package/lib/managers/server/routes.js +228 -220
- package/lib/managers/session.d.ts +3 -3
- package/lib/managers/session.js +125 -125
- package/lib/managers/socket.d.ts +3 -3
- package/lib/managers/socket.js +188 -186
- package/lib/managers/telemetry.d.ts +74 -74
- package/lib/managers/telemetry.js +215 -214
- package/lib/managers/test.js +84 -84
- package/lib/models/action.d.ts +2 -2
- package/lib/models/action.js +2 -2
- package/lib/models/audit.d.ts +15 -15
- package/lib/models/audit.js +2 -2
- package/lib/models/config-manager.d.ts +21 -21
- package/lib/models/config-manager.js +2 -2
- package/lib/models/config.d.ts +86 -86
- package/lib/models/config.js +2 -2
- package/lib/models/counter.d.ts +11 -11
- package/lib/models/counter.js +2 -2
- package/lib/models/errors.d.ts +15 -15
- package/lib/models/errors.js +2 -2
- package/lib/models/exercise-obj.d.ts +29 -30
- package/lib/models/exercise-obj.js +2 -2
- package/lib/models/file.d.ts +5 -5
- package/lib/models/file.js +2 -2
- package/lib/models/findings.d.ts +17 -17
- package/lib/models/findings.js +2 -2
- package/lib/models/flags.d.ts +10 -10
- package/lib/models/flags.js +2 -2
- package/lib/models/front-matter.d.ts +11 -11
- package/lib/models/front-matter.js +2 -2
- package/lib/models/gitpod-data.d.ts +16 -16
- package/lib/models/gitpod-data.js +2 -2
- package/lib/models/language.d.ts +4 -4
- package/lib/models/language.js +2 -2
- package/lib/models/package.d.ts +7 -7
- package/lib/models/package.js +2 -2
- package/lib/models/plugin-config.d.ts +16 -16
- package/lib/models/plugin-config.js +2 -2
- package/lib/models/session.d.ts +31 -31
- package/lib/models/session.js +2 -2
- package/lib/models/socket.d.ts +37 -37
- package/lib/models/socket.js +2 -2
- package/lib/models/status.d.ts +1 -1
- package/lib/models/status.js +2 -2
- package/lib/models/success-types.d.ts +1 -1
- package/lib/models/success-types.js +2 -2
- package/lib/plugin/command/compile.d.ts +6 -6
- package/lib/plugin/command/compile.js +18 -18
- package/lib/plugin/command/test.d.ts +6 -6
- package/lib/plugin/command/test.js +25 -25
- package/lib/plugin/index.d.ts +27 -27
- package/lib/plugin/index.js +7 -7
- package/lib/plugin/plugin.d.ts +8 -8
- package/lib/plugin/plugin.js +68 -68
- package/lib/plugin/utils.d.ts +16 -16
- package/lib/plugin/utils.js +58 -58
- package/lib/ui/download.d.ts +5 -5
- package/lib/ui/download.js +62 -61
- package/lib/utils/BaseCommand.d.ts +8 -8
- package/lib/utils/BaseCommand.js +41 -41
- package/lib/utils/SessionCommand.d.ts +10 -10
- package/lib/utils/SessionCommand.js +43 -43
- package/lib/utils/api.d.ts +14 -14
- package/lib/utils/api.js +255 -255
- package/lib/utils/audit.d.ts +16 -16
- package/lib/utils/audit.js +303 -303
- package/lib/utils/checkNotInstalled.d.ts +8 -8
- package/lib/utils/checkNotInstalled.js +185 -181
- package/lib/utils/console.d.ts +12 -12
- package/lib/utils/console.js +19 -19
- package/lib/utils/errors.d.ts +17 -17
- package/lib/utils/errors.js +107 -100
- package/lib/utils/exercisesQueue.d.ts +9 -9
- package/lib/utils/exercisesQueue.js +38 -38
- package/lib/utils/fileQueue.d.ts +43 -43
- package/lib/utils/fileQueue.js +169 -169
- package/lib/utils/misc.d.ts +1 -1
- package/lib/utils/misc.js +24 -23
- package/lib/utils/osOperations.d.ts +5 -5
- package/lib/utils/osOperations.js +72 -72
- package/lib/utils/validators.d.ts +5 -5
- package/lib/utils/validators.js +16 -17
- package/lib/utils/watcher.d.ts +2 -2
- package/lib/utils/watcher.js +25 -25
- package/oclif.manifest.json +1 -1
- package/package.json +6 -4
- package/src/commands/publish.ts +181 -107
- package/src/managers/config/index.ts +5 -0
- package/src/managers/server/routes.ts +10 -0
- package/src/managers/session.ts +145 -145
@@ -1,74 +1,74 @@
|
|
1
|
-
import { IFile } from "../models/file";
|
2
|
-
|
3
|
-
source_code: string;
|
4
|
-
stdout: string;
|
5
|
-
exit_code: number;
|
6
|
-
starting_at: number;
|
7
|
-
ending_at: number;
|
8
|
-
};
|
9
|
-
|
10
|
-
source_code: string;
|
11
|
-
stdout: string;
|
12
|
-
exit_code: number;
|
13
|
-
starting_at: number;
|
14
|
-
ending_at: number;
|
15
|
-
};
|
16
|
-
|
17
|
-
student_message: string;
|
18
|
-
source_code: string;
|
19
|
-
ai_response: string;
|
20
|
-
starting_at: number;
|
21
|
-
ending_at: number;
|
22
|
-
};
|
23
|
-
export
|
24
|
-
slug: string;
|
25
|
-
position: number;
|
26
|
-
files: IFile[];
|
27
|
-
is_testeable: boolean;
|
28
|
-
opened_at?: number;
|
29
|
-
completed_at?: number;
|
30
|
-
compilations: TCompilationAttempt[];
|
31
|
-
tests: TTestAttempt[];
|
32
|
-
ai_interactions: TAIInteraction[];
|
33
|
-
};
|
34
|
-
|
35
|
-
started_at: number;
|
36
|
-
ended_at?: number;
|
37
|
-
};
|
38
|
-
|
39
|
-
token: string;
|
40
|
-
user_id: string;
|
41
|
-
email: string;
|
42
|
-
};
|
43
|
-
export interface ITelemetryJSONSchema {
|
44
|
-
telemetry_id?: string;
|
45
|
-
user_id?: number | string;
|
46
|
-
slug: string;
|
47
|
-
agent?: string;
|
48
|
-
tutorial_started_at?: number;
|
49
|
-
last_interaction_at?: number;
|
50
|
-
steps: Array<TStep>;
|
51
|
-
workout_session: TWorkoutSession[];
|
52
|
-
}
|
53
|
-
|
54
|
-
export
|
55
|
-
streaming?: string;
|
56
|
-
batch?: string;
|
57
|
-
};
|
58
|
-
interface ITelemetryManager {
|
59
|
-
current: ITelemetryJSONSchema | null;
|
60
|
-
configPath: string | null;
|
61
|
-
urls: TTelemetryUrls;
|
62
|
-
salute: (message: string) => void;
|
63
|
-
start: (agent: string, steps: TStep[], path: string, tutorialSlug: string) => void;
|
64
|
-
prevStep?: number;
|
65
|
-
registerStepEvent: (stepPosition: number, event: TStepEvent, data: any) => void;
|
66
|
-
streamEvent: (stepPosition: number, event: string, data: any) => void;
|
67
|
-
submit: () => Promise<void>;
|
68
|
-
finishWorkoutSession: () => void;
|
69
|
-
setStudent: (student: TStudent) => void;
|
70
|
-
save: () => void;
|
71
|
-
retrieve: () => Promise<ITelemetryJSONSchema | null>;
|
72
|
-
}
|
73
|
-
declare const TelemetryManager: ITelemetryManager;
|
74
|
-
export default TelemetryManager;
|
1
|
+
import { IFile } from "../models/file";
|
2
|
+
type TCompilationAttempt = {
|
3
|
+
source_code: string;
|
4
|
+
stdout: string;
|
5
|
+
exit_code: number;
|
6
|
+
starting_at: number;
|
7
|
+
ending_at: number;
|
8
|
+
};
|
9
|
+
type TTestAttempt = {
|
10
|
+
source_code: string;
|
11
|
+
stdout: string;
|
12
|
+
exit_code: number;
|
13
|
+
starting_at: number;
|
14
|
+
ending_at: number;
|
15
|
+
};
|
16
|
+
type TAIInteraction = {
|
17
|
+
student_message: string;
|
18
|
+
source_code: string;
|
19
|
+
ai_response: string;
|
20
|
+
starting_at: number;
|
21
|
+
ending_at: number;
|
22
|
+
};
|
23
|
+
export type TStep = {
|
24
|
+
slug: string;
|
25
|
+
position: number;
|
26
|
+
files: IFile[];
|
27
|
+
is_testeable: boolean;
|
28
|
+
opened_at?: number;
|
29
|
+
completed_at?: number;
|
30
|
+
compilations: TCompilationAttempt[];
|
31
|
+
tests: TTestAttempt[];
|
32
|
+
ai_interactions: TAIInteraction[];
|
33
|
+
};
|
34
|
+
type TWorkoutSession = {
|
35
|
+
started_at: number;
|
36
|
+
ended_at?: number;
|
37
|
+
};
|
38
|
+
type TStudent = {
|
39
|
+
token: string;
|
40
|
+
user_id: string;
|
41
|
+
email: string;
|
42
|
+
};
|
43
|
+
export interface ITelemetryJSONSchema {
|
44
|
+
telemetry_id?: string;
|
45
|
+
user_id?: number | string;
|
46
|
+
slug: string;
|
47
|
+
agent?: string;
|
48
|
+
tutorial_started_at?: number;
|
49
|
+
last_interaction_at?: number;
|
50
|
+
steps: Array<TStep>;
|
51
|
+
workout_session: TWorkoutSession[];
|
52
|
+
}
|
53
|
+
type TStepEvent = "compile" | "test" | "ai_interaction" | "open_step";
|
54
|
+
export type TTelemetryUrls = {
|
55
|
+
streaming?: string;
|
56
|
+
batch?: string;
|
57
|
+
};
|
58
|
+
interface ITelemetryManager {
|
59
|
+
current: ITelemetryJSONSchema | null;
|
60
|
+
configPath: string | null;
|
61
|
+
urls: TTelemetryUrls;
|
62
|
+
salute: (message: string) => void;
|
63
|
+
start: (agent: string, steps: TStep[], path: string, tutorialSlug: string) => void;
|
64
|
+
prevStep?: number;
|
65
|
+
registerStepEvent: (stepPosition: number, event: TStepEvent, data: any) => void;
|
66
|
+
streamEvent: (stepPosition: number, event: string, data: any) => void;
|
67
|
+
submit: () => Promise<void>;
|
68
|
+
finishWorkoutSession: () => void;
|
69
|
+
setStudent: (student: TStudent) => void;
|
70
|
+
save: () => void;
|
71
|
+
retrieve: () => Promise<ITelemetryJSONSchema | null>;
|
72
|
+
}
|
73
|
+
declare const TelemetryManager: ITelemetryManager;
|
74
|
+
export default TelemetryManager;
|
@@ -1,214 +1,215 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const api_1 = require("../utils/api");
|
4
|
-
const console_1 = require("../utils/console");
|
5
|
-
const fs = require("fs");
|
6
|
-
function createUUID() {
|
7
|
-
return (Math.random().toString(36).slice(2, 10) +
|
8
|
-
Math.random().toString(36).slice(2, 10));
|
9
|
-
}
|
10
|
-
function stringToBase64(input) {
|
11
|
-
return Buffer.from(input).toString("base64");
|
12
|
-
}
|
13
|
-
const TelemetryManager = {
|
14
|
-
current: null,
|
15
|
-
urls: {},
|
16
|
-
configPath: "",
|
17
|
-
salute: message => {
|
18
|
-
console_1.default.info(message);
|
19
|
-
},
|
20
|
-
start: function (agent, steps, path, tutorialSlug) {
|
21
|
-
this.configPath = path;
|
22
|
-
if (!this.current) {
|
23
|
-
this.retrieve()
|
24
|
-
.then(data => {
|
25
|
-
const prevTelemetry = data;
|
26
|
-
if (prevTelemetry) {
|
27
|
-
this.current = prevTelemetry;
|
28
|
-
this.finishWorkoutSession();
|
29
|
-
}
|
30
|
-
else {
|
31
|
-
this.current = {
|
32
|
-
telemetry_id: createUUID(),
|
33
|
-
slug: tutorialSlug,
|
34
|
-
agent,
|
35
|
-
tutorial_started_at: Date.now(),
|
36
|
-
steps,
|
37
|
-
workout_session: [
|
38
|
-
{
|
39
|
-
started_at: Date.now(),
|
40
|
-
},
|
41
|
-
],
|
42
|
-
};
|
43
|
-
}
|
44
|
-
this.save();
|
45
|
-
this.submit();
|
46
|
-
})
|
47
|
-
.catch(error => {
|
48
|
-
console_1.default.debug(error);
|
49
|
-
// Delete the telemetry.json if it exists
|
50
|
-
fs.unlinkSync(`${this.configPath}/telemetry.json`);
|
51
|
-
throw new Error("There was a problem starting, reload LearnPack\nRun\n$ learnpack start");
|
52
|
-
});
|
53
|
-
}
|
54
|
-
},
|
55
|
-
// verifyStudent: function () {
|
56
|
-
// if (!this.current) {
|
57
|
-
// return;
|
58
|
-
// }
|
59
|
-
// if (!this.current.user_id) {
|
60
|
-
// }
|
61
|
-
// },
|
62
|
-
setStudent: function (student) {
|
63
|
-
if (!this.current) {
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
this.current.user_id = student.user_id;
|
67
|
-
this.save();
|
68
|
-
this.submit();
|
69
|
-
},
|
70
|
-
finishWorkoutSession: function () {
|
71
|
-
var _a, _b;
|
72
|
-
if (!this.current) {
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
const lastSession = (_a = this.current) === null || _a === void 0 ? void 0 : _a.workout_session[this.current.workout_session.length - 1];
|
76
|
-
if (lastSession &&
|
77
|
-
!lastSession.ended_at &&
|
78
|
-
|
79
|
-
this.current.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
data.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
this.
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
this.
|
153
|
-
this.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
resolve
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
const
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
}
|
214
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const api_1 = require("../utils/api");
|
4
|
+
const console_1 = require("../utils/console");
|
5
|
+
const fs = require("fs");
|
6
|
+
function createUUID() {
|
7
|
+
return (Math.random().toString(36).slice(2, 10) +
|
8
|
+
Math.random().toString(36).slice(2, 10));
|
9
|
+
}
|
10
|
+
function stringToBase64(input) {
|
11
|
+
return Buffer.from(input).toString("base64");
|
12
|
+
}
|
13
|
+
const TelemetryManager = {
|
14
|
+
current: null,
|
15
|
+
urls: {},
|
16
|
+
configPath: "",
|
17
|
+
salute: message => {
|
18
|
+
console_1.default.info(message);
|
19
|
+
},
|
20
|
+
start: function (agent, steps, path, tutorialSlug) {
|
21
|
+
this.configPath = path;
|
22
|
+
if (!this.current) {
|
23
|
+
this.retrieve()
|
24
|
+
.then(data => {
|
25
|
+
const prevTelemetry = data;
|
26
|
+
if (prevTelemetry) {
|
27
|
+
this.current = prevTelemetry;
|
28
|
+
this.finishWorkoutSession();
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
this.current = {
|
32
|
+
telemetry_id: createUUID(),
|
33
|
+
slug: tutorialSlug,
|
34
|
+
agent,
|
35
|
+
tutorial_started_at: Date.now(),
|
36
|
+
steps,
|
37
|
+
workout_session: [
|
38
|
+
{
|
39
|
+
started_at: Date.now(),
|
40
|
+
},
|
41
|
+
],
|
42
|
+
};
|
43
|
+
}
|
44
|
+
this.save();
|
45
|
+
this.submit();
|
46
|
+
})
|
47
|
+
.catch(error => {
|
48
|
+
console_1.default.debug(error);
|
49
|
+
// Delete the telemetry.json if it exists
|
50
|
+
fs.unlinkSync(`${this.configPath}/telemetry.json`);
|
51
|
+
throw new Error("There was a problem starting, reload LearnPack\nRun\n$ learnpack start");
|
52
|
+
});
|
53
|
+
}
|
54
|
+
},
|
55
|
+
// verifyStudent: function () {
|
56
|
+
// if (!this.current) {
|
57
|
+
// return;
|
58
|
+
// }
|
59
|
+
// if (!this.current.user_id) {
|
60
|
+
// }
|
61
|
+
// },
|
62
|
+
setStudent: function (student) {
|
63
|
+
if (!this.current) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
this.current.user_id = student.user_id;
|
67
|
+
this.save();
|
68
|
+
this.submit();
|
69
|
+
},
|
70
|
+
finishWorkoutSession: function () {
|
71
|
+
var _a, _b;
|
72
|
+
if (!this.current) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
const lastSession = (_a = this.current) === null || _a === void 0 ? void 0 : _a.workout_session[this.current.workout_session.length - 1];
|
76
|
+
if (lastSession &&
|
77
|
+
!lastSession.ended_at &&
|
78
|
+
((_b = this.current) === null || _b === void 0 ? void 0 : _b.last_interaction_at)) {
|
79
|
+
lastSession.ended_at = this.current.last_interaction_at;
|
80
|
+
this.current.workout_session.push({
|
81
|
+
started_at: Date.now(),
|
82
|
+
});
|
83
|
+
}
|
84
|
+
},
|
85
|
+
registerStepEvent: function (stepPosition, event, data) {
|
86
|
+
if (!this.current) {
|
87
|
+
// throw new Error("Telemetry has not been started");
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
const step = this.current.steps[stepPosition];
|
91
|
+
if (!step) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
if (data.source_code) {
|
95
|
+
data.source_code = stringToBase64(data.source_code);
|
96
|
+
}
|
97
|
+
if (data.stdout) {
|
98
|
+
data.stdout = stringToBase64(data.stdout);
|
99
|
+
}
|
100
|
+
if (data.stderr) {
|
101
|
+
data.stderr = stringToBase64(data.stderr);
|
102
|
+
}
|
103
|
+
if (Object.prototype.hasOwnProperty.call(data, "exitCode")) {
|
104
|
+
data.exit_code = data.exitCode;
|
105
|
+
data.exitCode = undefined;
|
106
|
+
}
|
107
|
+
switch (event) {
|
108
|
+
case "compile":
|
109
|
+
if (!step.compilations) {
|
110
|
+
step.compilations = [];
|
111
|
+
}
|
112
|
+
step.compilations.push(data);
|
113
|
+
this.current.steps[stepPosition] = step;
|
114
|
+
break;
|
115
|
+
case "test":
|
116
|
+
if (!step.tests) {
|
117
|
+
step.tests = [];
|
118
|
+
}
|
119
|
+
// data.stdout =
|
120
|
+
step.tests.push(data);
|
121
|
+
if (data.exit_code === 0) {
|
122
|
+
step.completed_at = Date.now();
|
123
|
+
}
|
124
|
+
this.current.steps[stepPosition] = step;
|
125
|
+
break;
|
126
|
+
case "ai_interaction":
|
127
|
+
if (!step.ai_interactions) {
|
128
|
+
step.ai_interactions = [];
|
129
|
+
}
|
130
|
+
step.ai_interactions.push(data);
|
131
|
+
break;
|
132
|
+
case "open_step": {
|
133
|
+
const now = Date.now();
|
134
|
+
if (!step.opened_at) {
|
135
|
+
step.opened_at = now;
|
136
|
+
this.current.steps[stepPosition] = step;
|
137
|
+
}
|
138
|
+
if (this.prevStep || this.prevStep === 0) {
|
139
|
+
const prevStep = this.current.steps[this.prevStep];
|
140
|
+
if (!prevStep.is_testeable && !prevStep.completed_at) {
|
141
|
+
prevStep.completed_at = now;
|
142
|
+
this.current.steps[this.prevStep] = prevStep;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
this.prevStep = stepPosition;
|
146
|
+
this.submit();
|
147
|
+
break;
|
148
|
+
}
|
149
|
+
default:
|
150
|
+
throw new Error(`Event type ${event} is not supported`);
|
151
|
+
}
|
152
|
+
this.current.last_interaction_at = Date.now();
|
153
|
+
this.streamEvent(stepPosition, event, data);
|
154
|
+
this.save();
|
155
|
+
},
|
156
|
+
retrieve: function () {
|
157
|
+
return new Promise((resolve, reject) => {
|
158
|
+
fs.readFile(`${this.configPath}/telemetry.json`, "utf8", (err, data) => {
|
159
|
+
if (err) {
|
160
|
+
if (err.code === "ENOENT") {
|
161
|
+
// File does not exist, resolve with undefined
|
162
|
+
resolve(null);
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
reject(err);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
else {
|
169
|
+
try {
|
170
|
+
resolve(JSON.parse(data));
|
171
|
+
}
|
172
|
+
catch (error) {
|
173
|
+
reject(error);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
});
|
177
|
+
});
|
178
|
+
},
|
179
|
+
submit: async function () {
|
180
|
+
console_1.default.debug("Submitting telemetry...");
|
181
|
+
if (!this.current)
|
182
|
+
return Promise.resolve();
|
183
|
+
const url = this.urls.batch;
|
184
|
+
if (!url) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
const body = this.current;
|
188
|
+
api_1.default.sendBatchTelemetry(url, body);
|
189
|
+
},
|
190
|
+
save: function () {
|
191
|
+
fs.writeFile(`${this.configPath}/telemetry.json`, JSON.stringify(this.current), (err) => {
|
192
|
+
if (err)
|
193
|
+
throw err;
|
194
|
+
});
|
195
|
+
},
|
196
|
+
streamEvent: async function (stepPosition, event, data) {
|
197
|
+
if (!this.current)
|
198
|
+
return;
|
199
|
+
const url = this.urls.streaming;
|
200
|
+
if (!url) {
|
201
|
+
return;
|
202
|
+
}
|
203
|
+
const stepSlug = this.current.steps[stepPosition].slug;
|
204
|
+
const body = {
|
205
|
+
slug: stepSlug,
|
206
|
+
telemetry_id: this.current.telemetry_id,
|
207
|
+
user_id: this.current.user_id,
|
208
|
+
step_position: stepPosition,
|
209
|
+
event,
|
210
|
+
data,
|
211
|
+
};
|
212
|
+
api_1.default.sendStreamTelemetry(url, body);
|
213
|
+
},
|
214
|
+
};
|
215
|
+
exports.default = TelemetryManager;
|