@learnpack/learnpack 2.1.34 → 2.1.36
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -10
- package/lib/commands/start.js +4 -2
- package/lib/managers/telemetry.d.ts +3 -2
- package/lib/managers/telemetry.js +11 -5
- package/lib/utils/api.js +16 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/start.ts +3 -1
- package/src/managers/telemetry.ts +21 -6
- package/src/utils/api.ts +22 -1
package/README.md
CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @learnpack/learnpack
|
|
21
21
|
$ learnpack COMMAND
|
22
22
|
running command...
|
23
23
|
$ learnpack (-v|--version|version)
|
24
|
-
@learnpack/learnpack/2.1.
|
24
|
+
@learnpack/learnpack/2.1.36 darwin-arm64 node-v16.20.0
|
25
25
|
$ learnpack --help [COMMAND]
|
26
26
|
USAGE
|
27
27
|
$ learnpack COMMAND
|
@@ -74,7 +74,7 @@ DESCRIPTION
|
|
74
74
|
12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
|
75
75
|
```
|
76
76
|
|
77
|
-
_See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
77
|
+
_See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/audit.ts)_
|
78
78
|
|
79
79
|
## `learnpack clean`
|
80
80
|
|
@@ -89,7 +89,7 @@ DESCRIPTION
|
|
89
89
|
Extra documentation goes here
|
90
90
|
```
|
91
91
|
|
92
|
-
_See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
92
|
+
_See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/clean.ts)_
|
93
93
|
|
94
94
|
## `learnpack download [PACKAGE]`
|
95
95
|
|
@@ -107,7 +107,7 @@ DESCRIPTION
|
|
107
107
|
Extra documentation goes here
|
108
108
|
```
|
109
109
|
|
110
|
-
_See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
110
|
+
_See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/download.ts)_
|
111
111
|
|
112
112
|
## `learnpack help [COMMAND]`
|
113
113
|
|
@@ -138,7 +138,7 @@ OPTIONS
|
|
138
138
|
-h, --grading show CLI help
|
139
139
|
```
|
140
140
|
|
141
|
-
_See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
141
|
+
_See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/init.ts)_
|
142
142
|
|
143
143
|
## `learnpack login [PACKAGE]`
|
144
144
|
|
@@ -156,7 +156,7 @@ DESCRIPTION
|
|
156
156
|
Extra documentation goes here
|
157
157
|
```
|
158
158
|
|
159
|
-
_See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
159
|
+
_See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/login.ts)_
|
160
160
|
|
161
161
|
## `learnpack logout [PACKAGE]`
|
162
162
|
|
@@ -174,7 +174,7 @@ DESCRIPTION
|
|
174
174
|
Extra documentation goes here
|
175
175
|
```
|
176
176
|
|
177
|
-
_See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
177
|
+
_See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/logout.ts)_
|
178
178
|
|
179
179
|
## `learnpack plugins`
|
180
180
|
|
@@ -309,7 +309,7 @@ DESCRIPTION
|
|
309
309
|
Extra documentation goes here
|
310
310
|
```
|
311
311
|
|
312
|
-
_See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
312
|
+
_See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/publish.ts)_
|
313
313
|
|
314
314
|
## `learnpack start`
|
315
315
|
|
@@ -330,7 +330,7 @@ OPTIONS
|
|
330
330
|
-w, --watch Watch for file changes
|
331
331
|
```
|
332
332
|
|
333
|
-
_See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
333
|
+
_See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/start.ts)_
|
334
334
|
|
335
335
|
## `learnpack test [EXERCISESLUG]`
|
336
336
|
|
@@ -344,7 +344,7 @@ ARGUMENTS
|
|
344
344
|
EXERCISESLUG The name of the exercise to test
|
345
345
|
```
|
346
346
|
|
347
|
-
_See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.
|
347
|
+
_See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.36/src/commands/test.ts)_
|
348
348
|
<!-- commandsstop -->
|
349
349
|
|
350
350
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
package/lib/commands/start.js
CHANGED
@@ -18,7 +18,7 @@ class StartCommand extends SessionCommand_1.default {
|
|
18
18
|
await this.initSession(flags);
|
19
19
|
}
|
20
20
|
async run() {
|
21
|
-
var _a, _b, _c, _d, _e;
|
21
|
+
var _a, _b, _c, _d, _e, _f;
|
22
22
|
// get configuration object
|
23
23
|
const configObject = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get();
|
24
24
|
const config = configObject === null || configObject === void 0 ? void 0 : configObject.config;
|
@@ -45,6 +45,8 @@ class StartCommand extends SessionCommand_1.default {
|
|
45
45
|
if (configObject.exercises) {
|
46
46
|
const agent = ((_d = configObject.config) === null || _d === void 0 ? void 0 : _d.editor.agent) || "";
|
47
47
|
const path = ((_e = configObject.config) === null || _e === void 0 ? void 0 : _e.dirPath) || "";
|
48
|
+
const tutorialSlug = ((_f = configObject.config) === null || _f === void 0 ? void 0 : _f.slug) || "";
|
49
|
+
console_1.default.info("Starting Telemetry with slug...", tutorialSlug);
|
48
50
|
const steps = configObject.exercises.map((e, index) => ({
|
49
51
|
slug: e.slug,
|
50
52
|
position: e.position || index,
|
@@ -55,7 +57,7 @@ class StartCommand extends SessionCommand_1.default {
|
|
55
57
|
is_testeable: e.graded || false,
|
56
58
|
}));
|
57
59
|
if (path && steps.length > 0) {
|
58
|
-
telemetry_1.default.start(agent, steps, path);
|
60
|
+
telemetry_1.default.start(agent, steps, path, tutorialSlug);
|
59
61
|
}
|
60
62
|
if (config.telemetry) {
|
61
63
|
telemetry_1.default.urls = config.telemetry;
|
@@ -42,7 +42,8 @@ declare type TStudent = {
|
|
42
42
|
};
|
43
43
|
export interface ITelemetryJSONSchema {
|
44
44
|
telemetry_id?: string;
|
45
|
-
|
45
|
+
user_id?: number | string;
|
46
|
+
slug: string;
|
46
47
|
agent?: string;
|
47
48
|
tutorial_started_at?: number;
|
48
49
|
last_interaction_at?: number;
|
@@ -59,7 +60,7 @@ interface ITelemetryManager {
|
|
59
60
|
configPath: string | null;
|
60
61
|
urls: TTelemetryUrls;
|
61
62
|
salute: (message: string) => void;
|
62
|
-
start: (agent: string, steps: TStep[], path: string) => void;
|
63
|
+
start: (agent: string, steps: TStep[], path: string, tutorialSlug: string) => void;
|
63
64
|
prevStep?: number;
|
64
65
|
registerStepEvent: (stepPosition: number, event: TStepEvent, data: any) => void;
|
65
66
|
streamEvent: (stepPosition: number, event: string, data: any) => void;
|
@@ -16,7 +16,7 @@ const TelemetryManager = {
|
|
16
16
|
salute: message => {
|
17
17
|
console.log(message);
|
18
18
|
},
|
19
|
-
start: function (agent, steps, path) {
|
19
|
+
start: function (agent, steps, path, tutorialSlug) {
|
20
20
|
this.configPath = path;
|
21
21
|
if (!this.current) {
|
22
22
|
this.retrieve(agent, steps)
|
@@ -29,6 +29,7 @@ const TelemetryManager = {
|
|
29
29
|
else {
|
30
30
|
this.current = {
|
31
31
|
telemetry_id: createUUID(),
|
32
|
+
slug: tutorialSlug,
|
32
33
|
agent,
|
33
34
|
tutorial_started_at: Date.now(),
|
34
35
|
steps,
|
@@ -47,11 +48,18 @@ const TelemetryManager = {
|
|
47
48
|
});
|
48
49
|
}
|
49
50
|
},
|
51
|
+
// verifyStudent: function () {
|
52
|
+
// if (!this.current) {
|
53
|
+
// return;
|
54
|
+
// }
|
55
|
+
// if (!this.current.user_id) {
|
56
|
+
// }
|
57
|
+
// },
|
50
58
|
setStudent: function (student) {
|
51
59
|
if (!this.current) {
|
52
60
|
return;
|
53
61
|
}
|
54
|
-
this.current.
|
62
|
+
this.current.user_id = student.user_id;
|
55
63
|
this.save();
|
56
64
|
this.submit();
|
57
65
|
},
|
@@ -171,19 +179,17 @@ const TelemetryManager = {
|
|
171
179
|
});
|
172
180
|
},
|
173
181
|
streamEvent: async function (stepPosition, event, data) {
|
174
|
-
var _a;
|
175
182
|
if (!this.current)
|
176
183
|
return;
|
177
184
|
const url = this.urls.streaming;
|
178
185
|
if (!url) {
|
179
186
|
return;
|
180
|
-
// throw new Error("Streaming URL not specified");
|
181
187
|
}
|
182
188
|
const stepSlug = this.current.steps[stepPosition].slug;
|
183
189
|
const body = {
|
184
190
|
slug: stepSlug,
|
185
191
|
telemetry_id: this.current.telemetry_id,
|
186
|
-
user_id:
|
192
|
+
user_id: this.current.user_id,
|
187
193
|
step_position: stepPosition,
|
188
194
|
event,
|
189
195
|
data,
|
package/lib/utils/api.js
CHANGED
@@ -23,7 +23,8 @@ const fetch = async (url, options = {}, returnAsJson = true) => {
|
|
23
23
|
return returnAsJson ? await resp.json() : await resp.text();
|
24
24
|
}
|
25
25
|
if (resp.status === 401)
|
26
|
-
|
26
|
+
console_1.default.debug("Invalid authentication credentials", `Code: 401`);
|
27
|
+
// throw APIError("Invalid authentication credentials", 401)
|
27
28
|
else if (resp.status === 404)
|
28
29
|
throw APIError("Package not found", 404);
|
29
30
|
else if (resp.status >= 500)
|
@@ -201,6 +202,13 @@ const sendBatchTelemetry = async function (url, body) {
|
|
201
202
|
if (!url) {
|
202
203
|
return;
|
203
204
|
}
|
205
|
+
const session = await storage.getItem("bc-payload");
|
206
|
+
if (!session ||
|
207
|
+
!Object.prototype.hasOwnProperty.call(session, "token") ||
|
208
|
+
session.token === "") {
|
209
|
+
console_1.default.debug("No token found, skipping stream telemetry delivery");
|
210
|
+
return;
|
211
|
+
}
|
204
212
|
fetch(url, {
|
205
213
|
method: "POST",
|
206
214
|
body: JSON.stringify(body),
|
@@ -216,6 +224,13 @@ const sendStreamTelemetry = async function (url, body) {
|
|
216
224
|
if (!url) {
|
217
225
|
return;
|
218
226
|
}
|
227
|
+
const session = await storage.getItem("bc-payload");
|
228
|
+
if (!session ||
|
229
|
+
!Object.prototype.hasOwnProperty.call(session, "token") ||
|
230
|
+
session.token === "") {
|
231
|
+
console_1.default.debug("No token found, skipping stream telemetry delivery");
|
232
|
+
return;
|
233
|
+
}
|
219
234
|
fetch(url, {
|
220
235
|
method: "POST",
|
221
236
|
body: JSON.stringify(body),
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"2.1.
|
1
|
+
{"version":"2.1.36","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[standalone, gitpod]","options":["standalone","gitpod"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]}}}
|
package/package.json
CHANGED
package/src/commands/start.ts
CHANGED
@@ -119,7 +119,9 @@ export default class StartCommand extends SessionCommand {
|
|
119
119
|
if (configObject.exercises) {
|
120
120
|
const agent = configObject.config?.editor.agent || ""
|
121
121
|
const path = configObject.config?.dirPath || ""
|
122
|
+
const tutorialSlug = configObject.config?.slug || ""
|
122
123
|
|
124
|
+
Console.info("Starting Telemetry with slug...", tutorialSlug)
|
123
125
|
const steps = configObject.exercises.map(
|
124
126
|
(e: IExercise, index): TStep => ({
|
125
127
|
slug: e.slug,
|
@@ -132,7 +134,7 @@ export default class StartCommand extends SessionCommand {
|
|
132
134
|
})
|
133
135
|
)
|
134
136
|
if (path && steps.length > 0) {
|
135
|
-
TelemetryManager.start(agent, steps, path)
|
137
|
+
TelemetryManager.start(agent, steps, path, tutorialSlug)
|
136
138
|
}
|
137
139
|
|
138
140
|
if (config.telemetry) {
|
@@ -62,7 +62,8 @@ type TStudent = {
|
|
62
62
|
|
63
63
|
export interface ITelemetryJSONSchema {
|
64
64
|
telemetry_id?: string;
|
65
|
-
|
65
|
+
user_id?: number | string;
|
66
|
+
slug: string;
|
66
67
|
agent?: string;
|
67
68
|
tutorial_started_at?: number;
|
68
69
|
last_interaction_at?: number;
|
@@ -83,7 +84,12 @@ interface ITelemetryManager {
|
|
83
84
|
configPath: string | null;
|
84
85
|
urls: TTelemetryUrls;
|
85
86
|
salute: (message: string) => void;
|
86
|
-
start: (
|
87
|
+
start: (
|
88
|
+
agent: string,
|
89
|
+
steps: TStep[],
|
90
|
+
path: string,
|
91
|
+
tutorialSlug: string
|
92
|
+
) => void;
|
87
93
|
prevStep?: number;
|
88
94
|
registerStepEvent: (
|
89
95
|
stepPosition: number,
|
@@ -109,7 +115,7 @@ const TelemetryManager: ITelemetryManager = {
|
|
109
115
|
console.log(message)
|
110
116
|
},
|
111
117
|
|
112
|
-
start: function (agent, steps, path) {
|
118
|
+
start: function (agent, steps, path, tutorialSlug) {
|
113
119
|
this.configPath = path
|
114
120
|
if (!this.current) {
|
115
121
|
this.retrieve(agent, steps)
|
@@ -121,6 +127,7 @@ const TelemetryManager: ITelemetryManager = {
|
|
121
127
|
} else {
|
122
128
|
this.current = {
|
123
129
|
telemetry_id: createUUID(),
|
130
|
+
slug: tutorialSlug,
|
124
131
|
agent,
|
125
132
|
tutorial_started_at: Date.now(),
|
126
133
|
steps,
|
@@ -140,13 +147,22 @@ const TelemetryManager: ITelemetryManager = {
|
|
140
147
|
})
|
141
148
|
}
|
142
149
|
},
|
150
|
+
// verifyStudent: function () {
|
151
|
+
// if (!this.current) {
|
152
|
+
// return;
|
153
|
+
// }
|
154
|
+
|
155
|
+
// if (!this.current.user_id) {
|
156
|
+
|
157
|
+
// }
|
158
|
+
// },
|
143
159
|
|
144
160
|
setStudent: function (student) {
|
145
161
|
if (!this.current) {
|
146
162
|
return
|
147
163
|
}
|
148
164
|
|
149
|
-
this.current.
|
165
|
+
this.current.user_id = student.user_id
|
150
166
|
this.save()
|
151
167
|
this.submit()
|
152
168
|
},
|
@@ -301,7 +317,6 @@ return
|
|
301
317
|
const url = this.urls.streaming
|
302
318
|
if (!url) {
|
303
319
|
return
|
304
|
-
// throw new Error("Streaming URL not specified");
|
305
320
|
}
|
306
321
|
|
307
322
|
const stepSlug = this.current.steps[stepPosition].slug
|
@@ -309,7 +324,7 @@ return
|
|
309
324
|
const body = {
|
310
325
|
slug: stepSlug,
|
311
326
|
telemetry_id: this.current.telemetry_id,
|
312
|
-
user_id: this.current.
|
327
|
+
user_id: this.current.user_id,
|
313
328
|
step_position: stepPosition,
|
314
329
|
event,
|
315
330
|
data,
|
package/src/utils/api.ts
CHANGED
@@ -43,7 +43,8 @@ const fetch = async (
|
|
43
43
|
}
|
44
44
|
|
45
45
|
if (resp.status === 401)
|
46
|
-
|
46
|
+
Console.debug("Invalid authentication credentials", `Code: 401`)
|
47
|
+
// throw APIError("Invalid authentication credentials", 401)
|
47
48
|
else if (resp.status === 404)
|
48
49
|
throw APIError("Package not found", 404)
|
49
50
|
else if (resp.status >= 500)
|
@@ -232,6 +233,16 @@ const sendBatchTelemetry = async function (url: string, body: object) {
|
|
232
233
|
return
|
233
234
|
}
|
234
235
|
|
236
|
+
const session = await storage.getItem("bc-payload")
|
237
|
+
if (
|
238
|
+
!session ||
|
239
|
+
!Object.prototype.hasOwnProperty.call(session, "token") ||
|
240
|
+
session.token === ""
|
241
|
+
) {
|
242
|
+
Console.debug("No token found, skipping stream telemetry delivery")
|
243
|
+
return
|
244
|
+
}
|
245
|
+
|
235
246
|
fetch(
|
236
247
|
url,
|
237
248
|
{
|
@@ -253,6 +264,16 @@ const sendStreamTelemetry = async function (url: string, body: object) {
|
|
253
264
|
return
|
254
265
|
}
|
255
266
|
|
267
|
+
const session = await storage.getItem("bc-payload")
|
268
|
+
if (
|
269
|
+
!session ||
|
270
|
+
!Object.prototype.hasOwnProperty.call(session, "token") ||
|
271
|
+
session.token === ""
|
272
|
+
) {
|
273
|
+
Console.debug("No token found, skipping stream telemetry delivery")
|
274
|
+
return
|
275
|
+
}
|
276
|
+
|
256
277
|
fetch(
|
257
278
|
url,
|
258
279
|
{
|