@learnpack/learnpack 4.0.10 → 4.0.13

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