@learnpack/learnpack 2.1.33 → 2.1.34
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -10
- package/lib/managers/telemetry.js +3 -28
- package/lib/utils/api.d.ts +2 -0
- package/lib/utils/api.js +37 -4
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/managers/telemetry.ts +4 -28
- package/src/utils/api.ts +54 -4
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.34 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.34/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.34/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.34/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.34/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.34/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.34/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.34/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.34/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.34/src/commands/test.ts)_
|
348
348
|
<!-- commandsstop -->
|
349
349
|
|
350
350
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const api_1 = require("../utils/api");
|
3
4
|
const fs = require("fs");
|
4
5
|
function createUUID() {
|
5
6
|
return (Math.random().toString(36).slice(2, 10) +
|
@@ -159,22 +160,9 @@ const TelemetryManager = {
|
|
159
160
|
const url = this.urls.batch;
|
160
161
|
if (!url) {
|
161
162
|
return;
|
162
|
-
// throw new Error("Batch URL not specified");
|
163
163
|
}
|
164
164
|
const body = this.current;
|
165
|
-
|
166
|
-
method: "POST",
|
167
|
-
headers: {
|
168
|
-
"Content-Type": "application/json",
|
169
|
-
},
|
170
|
-
body: JSON.stringify(body),
|
171
|
-
})
|
172
|
-
.then(response => {
|
173
|
-
return response.text();
|
174
|
-
})
|
175
|
-
.catch(error => {
|
176
|
-
console.log("Error", error);
|
177
|
-
});
|
165
|
+
api_1.default.sendBatchTelemetry(url, body);
|
178
166
|
},
|
179
167
|
save: function () {
|
180
168
|
fs.writeFile(`${this.configPath}/telemetry.json`, JSON.stringify(this.current), (err) => {
|
@@ -200,20 +188,7 @@ const TelemetryManager = {
|
|
200
188
|
event,
|
201
189
|
data,
|
202
190
|
};
|
203
|
-
|
204
|
-
const response = await fetch(url, {
|
205
|
-
method: "POST",
|
206
|
-
headers: {
|
207
|
-
"Content-Type": "application/json",
|
208
|
-
},
|
209
|
-
body: JSON.stringify(body),
|
210
|
-
});
|
211
|
-
const responseText = await response.text();
|
212
|
-
}
|
213
|
-
catch (error) {
|
214
|
-
error;
|
215
|
-
// Console.error(error);
|
216
|
-
}
|
191
|
+
api_1.default.sendStreamTelemetry(url, body);
|
217
192
|
},
|
218
193
|
};
|
219
194
|
exports.default = TelemetryManager;
|
package/lib/utils/api.d.ts
CHANGED
@@ -8,5 +8,7 @@ declare const _default: {
|
|
8
8
|
lang?: string | undefined;
|
9
9
|
slug?: string | undefined;
|
10
10
|
}) => Promise<any>;
|
11
|
+
sendBatchTelemetry: (url: string, body: object) => Promise<void>;
|
12
|
+
sendStreamTelemetry: (url: string, body: object) => Promise<void>;
|
11
13
|
};
|
12
14
|
export default _default;
|
package/lib/utils/api.js
CHANGED
@@ -7,9 +7,9 @@ const HOST = "https://breathecode.herokuapp.com";
|
|
7
7
|
const RIGOBOT_HOST = "https://rigobot.herokuapp.com";
|
8
8
|
// eslint-disable-next-line
|
9
9
|
const _fetch = require("node-fetch");
|
10
|
-
const fetch = async (url, options = {}) => {
|
10
|
+
const fetch = async (url, options = {}, returnAsJson = true) => {
|
11
11
|
const headers = { "Content-Type": "application/json" };
|
12
|
-
console_1.default.
|
12
|
+
console_1.default.debug(`Fetching ${url}`);
|
13
13
|
let session = null;
|
14
14
|
try {
|
15
15
|
session = await storage.getItem("bc-payload");
|
@@ -19,8 +19,9 @@ const fetch = async (url, options = {}) => {
|
|
19
19
|
catch (_a) { }
|
20
20
|
try {
|
21
21
|
const resp = await _fetch(url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, headers), options.headers) }));
|
22
|
-
if (resp.status >= 200 && resp.status < 300)
|
23
|
-
return await resp.json();
|
22
|
+
if (resp.status >= 200 && resp.status < 300) {
|
23
|
+
return returnAsJson ? await resp.json() : await resp.text();
|
24
|
+
}
|
24
25
|
if (resp.status === 401)
|
25
26
|
throw APIError("Invalid authentication credentials", 401);
|
26
27
|
else if (resp.status === 404)
|
@@ -196,6 +197,36 @@ const APIError = (error, code) => {
|
|
196
197
|
_err.status = code || 400;
|
197
198
|
return _err;
|
198
199
|
};
|
200
|
+
const sendBatchTelemetry = async function (url, body) {
|
201
|
+
if (!url) {
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
fetch(url, {
|
205
|
+
method: "POST",
|
206
|
+
body: JSON.stringify(body),
|
207
|
+
}, false)
|
208
|
+
.then(response => {
|
209
|
+
return response.text();
|
210
|
+
})
|
211
|
+
.catch(error => {
|
212
|
+
console_1.default.debug("Error while sending batch Telemetry", error);
|
213
|
+
});
|
214
|
+
};
|
215
|
+
const sendStreamTelemetry = async function (url, body) {
|
216
|
+
if (!url) {
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
fetch(url, {
|
220
|
+
method: "POST",
|
221
|
+
body: JSON.stringify(body),
|
222
|
+
}, false)
|
223
|
+
.then(response => {
|
224
|
+
return response;
|
225
|
+
})
|
226
|
+
.catch(error => {
|
227
|
+
console_1.default.debug("Error while sending stream Telemetry", error);
|
228
|
+
});
|
229
|
+
};
|
199
230
|
exports.default = {
|
200
231
|
login,
|
201
232
|
publish,
|
@@ -203,4 +234,6 @@ exports.default = {
|
|
203
234
|
getPackage,
|
204
235
|
getLangs,
|
205
236
|
getAllPackages,
|
237
|
+
sendBatchTelemetry,
|
238
|
+
sendStreamTelemetry,
|
206
239
|
};
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"2.1.
|
1
|
+
{"version":"2.1.34","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
@@ -1,5 +1,5 @@
|
|
1
1
|
import { IFile } from "../models/file"
|
2
|
-
|
2
|
+
import API from "../utils/api"
|
3
3
|
const fs = require("fs")
|
4
4
|
|
5
5
|
function createUUID(): string {
|
@@ -277,23 +277,11 @@ return Promise.resolve()
|
|
277
277
|
const url = this.urls.batch
|
278
278
|
if (!url) {
|
279
279
|
return
|
280
|
-
// throw new Error("Batch URL not specified");
|
281
280
|
}
|
282
281
|
|
283
282
|
const body = this.current
|
284
|
-
|
285
|
-
|
286
|
-
headers: {
|
287
|
-
"Content-Type": "application/json",
|
288
|
-
},
|
289
|
-
body: JSON.stringify(body),
|
290
|
-
})
|
291
|
-
.then(response => {
|
292
|
-
return response.text()
|
293
|
-
})
|
294
|
-
.catch(error => {
|
295
|
-
console.log("Error", error)
|
296
|
-
})
|
283
|
+
|
284
|
+
API.sendBatchTelemetry(url, body)
|
297
285
|
},
|
298
286
|
save: function () {
|
299
287
|
fs.writeFile(
|
@@ -327,19 +315,7 @@ return
|
|
327
315
|
data,
|
328
316
|
}
|
329
317
|
|
330
|
-
|
331
|
-
const response = await fetch(url, {
|
332
|
-
method: "POST",
|
333
|
-
headers: {
|
334
|
-
"Content-Type": "application/json",
|
335
|
-
},
|
336
|
-
body: JSON.stringify(body),
|
337
|
-
})
|
338
|
-
const responseText = await response.text()
|
339
|
-
} catch (error) {
|
340
|
-
error
|
341
|
-
// Console.error(error);
|
342
|
-
}
|
318
|
+
API.sendStreamTelemetry(url, body)
|
343
319
|
},
|
344
320
|
}
|
345
321
|
|
package/src/utils/api.ts
CHANGED
@@ -18,9 +18,13 @@ interface IOptions {
|
|
18
18
|
body?: string;
|
19
19
|
}
|
20
20
|
|
21
|
-
const fetch = async (
|
21
|
+
const fetch = async (
|
22
|
+
url: string,
|
23
|
+
options: IOptions = {},
|
24
|
+
returnAsJson = true
|
25
|
+
) => {
|
22
26
|
const headers: IHeaders = { "Content-Type": "application/json" }
|
23
|
-
Console.
|
27
|
+
Console.debug(`Fetching ${url}`)
|
24
28
|
let session = null
|
25
29
|
try {
|
26
30
|
session = await storage.getItem("bc-payload")
|
@@ -34,8 +38,10 @@ const fetch = async (url: string, options: IOptions = {}) => {
|
|
34
38
|
headers: { ...headers, ...options.headers },
|
35
39
|
} as any)
|
36
40
|
|
37
|
-
if (resp.status >= 200 && resp.status < 300)
|
38
|
-
return await resp.json()
|
41
|
+
if (resp.status >= 200 && resp.status < 300) {
|
42
|
+
return returnAsJson ? await resp.json() : await resp.text()
|
43
|
+
}
|
44
|
+
|
39
45
|
if (resp.status === 401)
|
40
46
|
throw APIError("Invalid authentication credentials", 401)
|
41
47
|
else if (resp.status === 404)
|
@@ -221,6 +227,48 @@ const APIError = (error: TypeError | string, code?: number) => {
|
|
221
227
|
return _err
|
222
228
|
}
|
223
229
|
|
230
|
+
const sendBatchTelemetry = async function (url: string, body: object) {
|
231
|
+
if (!url) {
|
232
|
+
return
|
233
|
+
}
|
234
|
+
|
235
|
+
fetch(
|
236
|
+
url,
|
237
|
+
{
|
238
|
+
method: "POST",
|
239
|
+
body: JSON.stringify(body),
|
240
|
+
},
|
241
|
+
false
|
242
|
+
)
|
243
|
+
.then(response => {
|
244
|
+
return response.text()
|
245
|
+
})
|
246
|
+
.catch(error => {
|
247
|
+
Console.debug("Error while sending batch Telemetry", error)
|
248
|
+
})
|
249
|
+
}
|
250
|
+
|
251
|
+
const sendStreamTelemetry = async function (url: string, body: object) {
|
252
|
+
if (!url) {
|
253
|
+
return
|
254
|
+
}
|
255
|
+
|
256
|
+
fetch(
|
257
|
+
url,
|
258
|
+
{
|
259
|
+
method: "POST",
|
260
|
+
body: JSON.stringify(body),
|
261
|
+
},
|
262
|
+
false
|
263
|
+
)
|
264
|
+
.then(response => {
|
265
|
+
return response
|
266
|
+
})
|
267
|
+
.catch(error => {
|
268
|
+
Console.debug("Error while sending stream Telemetry", error)
|
269
|
+
})
|
270
|
+
}
|
271
|
+
|
224
272
|
export default {
|
225
273
|
login,
|
226
274
|
publish,
|
@@ -228,4 +276,6 @@ export default {
|
|
228
276
|
getPackage,
|
229
277
|
getLangs,
|
230
278
|
getAllPackages,
|
279
|
+
sendBatchTelemetry,
|
280
|
+
sendStreamTelemetry,
|
231
281
|
}
|