@learnpack/learnpack 5.0.311 → 5.0.312

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.
@@ -1,4 +1,4 @@
1
- import { ISolution, IError } from '../models/errors';
1
+ import { ISolution, IError } from "../models/errors";
2
2
  export declare const getSolution: (slug?: string) => ISolution;
3
3
  export declare const ValidationError: (error: IError | string) => IError;
4
4
  export declare const NotFoundError: (error: IError | string) => IError;
@@ -2,32 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InternalError = exports.AuthError = exports.TestingError = exports.CompilerError = exports.NotFoundError = exports.ValidationError = exports.getSolution = void 0;
4
4
  const console_1 = require("./console");
5
- // eslint-disable-next-line
6
- const fetch = require("node-fetch");
7
- let solutions = null;
5
+ const solutions = {
6
+ "install-jest": {
7
+ gif: "",
8
+ video: "",
9
+ message: "You need to install jest",
10
+ },
11
+ };
8
12
  const uknown = {
9
- video: 'https://www.youtube.com/watch?v=gD1Sa99GiE4',
10
- message: 'Uknown internal error',
11
- slug: 'uknown',
12
- gif: 'https://github.com/breatheco-de/breathecode-cli/blob/master/docs/errors/uknown.gif?raw=true',
13
+ video: "https://www.youtube.com/watch?v=gD1Sa99GiE4",
14
+ message: "Uknown internal error",
15
+ slug: "uknown",
16
+ gif: "https://github.com/breatheco-de/breathecode-cli/blob/master/docs/errors/uknown.gif?raw=true",
13
17
  };
14
18
  const getSolution = (slug) => {
15
19
  if (!slug) {
16
- console_1.default.debug('Getting solution templates from the learnpack repository');
20
+ console_1.default.debug("Getting solution templates from the learnpack repository");
17
21
  }
18
22
  else {
19
23
  console_1.default.debug(`Getting solution for ${slug}`, solutions);
20
24
  }
21
- if (!solutions) {
22
- console_1.default.debug('Fetching for errors.json on github');
23
- fetch('https://raw.githubusercontent.com/breatheco-de/breathecode-cli/master/docs/errors/errors.json')
24
- .then((r) => r.json())
25
- .then(function (_s) {
26
- solutions = _s;
27
- });
28
- return uknown;
29
- }
30
- return typeof solutions[slug || ''] === 'undefined' || !slug ?
25
+ return typeof solutions[slug || ""] === "undefined" || !slug ?
31
26
  uknown :
32
27
  solutions[slug];
33
28
  };
@@ -36,11 +31,11 @@ const ValidationError = (error) => {
36
31
  const message = error.message || error;
37
32
  const _err = new Error(message);
38
33
  _err.status = 400;
39
- _err.type = 'validation-error';
34
+ _err.type = "validation-error";
40
35
  const sol = (0, exports.getSolution)(error.slug);
41
36
  _err.video = sol.video;
42
37
  _err.gif = sol.gif;
43
- _err.message = typeof message === 'string' ? message : sol.message;
38
+ _err.message = typeof message === "string" ? message : sol.message;
44
39
  return _err;
45
40
  };
46
41
  exports.ValidationError = ValidationError;
@@ -48,11 +43,11 @@ const NotFoundError = (error) => {
48
43
  const message = error.message || error;
49
44
  const _err = new Error(message);
50
45
  _err.status = 400;
51
- _err.type = 'not-found-error';
46
+ _err.type = "not-found-error";
52
47
  const sol = (0, exports.getSolution)(error.slug);
53
48
  _err.video = sol.video;
54
49
  _err.gif = sol.gif;
55
- _err.message = typeof message === 'string' ? message : sol.message;
50
+ _err.message = typeof message === "string" ? message : sol.message;
56
51
  return _err;
57
52
  };
58
53
  exports.NotFoundError = NotFoundError;
@@ -60,11 +55,11 @@ const CompilerError = (error) => {
60
55
  const message = error.message || error;
61
56
  const _err = new Error(message);
62
57
  _err.status = 400;
63
- _err.type = 'compiler-error';
58
+ _err.type = "compiler-error";
64
59
  const sol = (0, exports.getSolution)(error.slug);
65
60
  _err.video = sol.video;
66
61
  _err.gif = sol.gif;
67
- _err.message = typeof message === 'string' ? message : sol.message;
62
+ _err.message = typeof message === "string" ? message : sol.message;
68
63
  return _err;
69
64
  };
70
65
  exports.CompilerError = CompilerError;
@@ -72,7 +67,7 @@ const TestingError = (error) => {
72
67
  const message = error.message || error;
73
68
  const _err = new Error(message);
74
69
  _err.status = 400;
75
- _err.type = 'testing-error';
70
+ _err.type = "testing-error";
76
71
  return _err;
77
72
  };
78
73
  exports.TestingError = TestingError;
@@ -80,7 +75,7 @@ const AuthError = (error) => {
80
75
  const message = error.message || error;
81
76
  const _err = new Error(message);
82
77
  _err.status = 403;
83
- _err.type = 'auth-error';
78
+ _err.type = "auth-error";
84
79
  return _err;
85
80
  };
86
81
  exports.AuthError = AuthError;
@@ -88,11 +83,11 @@ const InternalError = (error) => {
88
83
  const message = error.message || error;
89
84
  const _err = new Error(message);
90
85
  _err.status = 500;
91
- _err.type = 'internal-error';
86
+ _err.type = "internal-error";
92
87
  const sol = (0, exports.getSolution)(error.slug);
93
88
  _err.video = sol.video;
94
89
  _err.gif = sol.gif;
95
- _err.message = typeof message === 'string' ? message : sol.message;
90
+ _err.message = typeof message === "string" ? message : sol.message;
96
91
  return _err;
97
92
  };
98
93
  exports.InternalError = InternalError;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@learnpack/learnpack",
3
3
  "description": "Seamlessly build, sell and/or take interactive & auto-graded tutorials, start learning now or build a new tutorial to your audience.",
4
- "version": "5.0.311",
4
+ "version": "5.0.312",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "contributors": [
7
7
  {
@@ -1,117 +1,108 @@
1
- import Console from './console'
2
-
3
- import {ISolution, IError} from '../models/errors'
4
-
5
- // eslint-disable-next-line
6
- const fetch = require("node-fetch");
7
-
8
- let solutions: { [key: string]: ISolution } | null = null
9
-
10
- const uknown: ISolution = {
11
- video: 'https://www.youtube.com/watch?v=gD1Sa99GiE4',
12
- message: 'Uknown internal error',
13
- slug: 'uknown',
14
- gif: 'https://github.com/breatheco-de/breathecode-cli/blob/master/docs/errors/uknown.gif?raw=true',
15
- }
16
-
17
- export const getSolution = (slug?: string): ISolution => {
18
- if (!slug) {
19
- Console.debug('Getting solution templates from the learnpack repository')
20
- } else {
21
- Console.debug(`Getting solution for ${slug}`, solutions)
22
- }
23
-
24
- if (!solutions) {
25
- Console.debug('Fetching for errors.json on github')
26
- fetch(
27
- 'https://raw.githubusercontent.com/breatheco-de/breathecode-cli/master/docs/errors/errors.json',
28
- )
29
- .then((r: Response) => r.json())
30
- .then(function (_s: { [key: string]: ISolution }) {
31
- solutions = _s
32
- })
33
- return uknown
34
- }
35
-
36
- return typeof solutions[slug || ''] === 'undefined' || !slug ?
37
- uknown :
38
- solutions[slug]
39
- }
40
-
41
- export const ValidationError = (error: IError | string) => {
42
- const message: string = (error as IError).message || (error as string)
43
- const _err = new Error(message) as IError
44
- _err.status = 400
45
- _err.type = 'validation-error'
46
-
47
- const sol: ISolution = getSolution((error as IError).slug)
48
- _err.video = sol.video
49
- _err.gif = sol.gif
50
- _err.message = typeof message === 'string' ? message : sol.message
51
- return _err
52
- }
53
-
54
- export const NotFoundError = (error: IError | string) => {
55
- const message = (error as IError).message || (error as string)
56
- const _err = new Error(message) as IError
57
- _err.status = 400
58
- _err.type = 'not-found-error'
59
-
60
- const sol = getSolution((error as IError).slug)
61
- _err.video = sol.video
62
- _err.gif = sol.gif
63
- _err.message = typeof message === 'string' ? message : sol.message
64
- return _err
65
- }
66
-
67
- export const CompilerError = (error: IError | string) => {
68
- const message = (error as IError).message || (error as string)
69
- const _err = new Error(message) as IError
70
- _err.status = 400
71
- _err.type = 'compiler-error'
72
-
73
- const sol = getSolution((error as IError).slug)
74
- _err.video = sol.video
75
- _err.gif = sol.gif
76
- _err.message = typeof message === 'string' ? message : sol.message
77
- return _err
78
- }
79
-
80
- export const TestingError = (error: IError | string) => {
81
- const message = (error as IError).message || (error as string)
82
- const _err = new Error(message) as IError
83
- _err.status = 400
84
- _err.type = 'testing-error'
85
- return _err
86
- }
87
-
88
- export const AuthError = (error: IError | string) => {
89
- const message = (error as IError).message || (error as string)
90
- const _err = new Error(message) as IError
91
- _err.status = 403
92
- _err.type = 'auth-error'
93
- return _err
94
- }
95
-
96
- export const InternalError = (error: IError | string) => {
97
- const message = (error as IError).message || (error as string)
98
- const _err = new Error(message) as IError
99
- _err.status = 500
100
- _err.type = 'internal-error'
101
-
102
- const sol = getSolution((error as IError).slug)
103
- _err.video = sol.video
104
- _err.gif = sol.gif
105
- _err.message = typeof message === 'string' ? message : sol.message
106
- return _err
107
- }
108
-
109
- getSolution()
110
- export default {
111
- ValidationError,
112
- CompilerError,
113
- TestingError,
114
- NotFoundError,
115
- InternalError,
116
- AuthError,
117
- }
1
+ import Console from "./console"
2
+
3
+ import { ISolution, IError } from "../models/errors"
4
+
5
+ const solutions: { [key: string]: ISolution } = {
6
+ "install-jest": {
7
+ gif: "",
8
+ video: "",
9
+ message: "You need to install jest",
10
+ },
11
+ }
12
+
13
+ const uknown: ISolution = {
14
+ video: "https://www.youtube.com/watch?v=gD1Sa99GiE4",
15
+ message: "Uknown internal error",
16
+ slug: "uknown",
17
+ gif: "https://github.com/breatheco-de/breathecode-cli/blob/master/docs/errors/uknown.gif?raw=true",
18
+ }
19
+
20
+ export const getSolution = (slug?: string): ISolution => {
21
+ if (!slug) {
22
+ Console.debug("Getting solution templates from the learnpack repository")
23
+ } else {
24
+ Console.debug(`Getting solution for ${slug}`, solutions)
25
+ }
26
+
27
+ return typeof solutions[slug || ""] === "undefined" || !slug ?
28
+ uknown :
29
+ solutions[slug]
30
+ }
31
+
32
+ export const ValidationError = (error: IError | string) => {
33
+ const message: string = (error as IError).message || (error as string)
34
+ const _err = new Error(message) as IError
35
+ _err.status = 400
36
+ _err.type = "validation-error"
37
+
38
+ const sol: ISolution = getSolution((error as IError).slug)
39
+ _err.video = sol.video
40
+ _err.gif = sol.gif
41
+ _err.message = typeof message === "string" ? message : sol.message
42
+ return _err
43
+ }
44
+
45
+ export const NotFoundError = (error: IError | string) => {
46
+ const message = (error as IError).message || (error as string)
47
+ const _err = new Error(message) as IError
48
+ _err.status = 400
49
+ _err.type = "not-found-error"
50
+
51
+ const sol = getSolution((error as IError).slug)
52
+ _err.video = sol.video
53
+ _err.gif = sol.gif
54
+ _err.message = typeof message === "string" ? message : sol.message
55
+ return _err
56
+ }
57
+
58
+ export const CompilerError = (error: IError | string) => {
59
+ const message = (error as IError).message || (error as string)
60
+ const _err = new Error(message) as IError
61
+ _err.status = 400
62
+ _err.type = "compiler-error"
63
+
64
+ const sol = getSolution((error as IError).slug)
65
+ _err.video = sol.video
66
+ _err.gif = sol.gif
67
+ _err.message = typeof message === "string" ? message : sol.message
68
+ return _err
69
+ }
70
+
71
+ export const TestingError = (error: IError | string) => {
72
+ const message = (error as IError).message || (error as string)
73
+ const _err = new Error(message) as IError
74
+ _err.status = 400
75
+ _err.type = "testing-error"
76
+ return _err
77
+ }
78
+
79
+ export const AuthError = (error: IError | string) => {
80
+ const message = (error as IError).message || (error as string)
81
+ const _err = new Error(message) as IError
82
+ _err.status = 403
83
+ _err.type = "auth-error"
84
+ return _err
85
+ }
86
+
87
+ export const InternalError = (error: IError | string) => {
88
+ const message = (error as IError).message || (error as string)
89
+ const _err = new Error(message) as IError
90
+ _err.status = 500
91
+ _err.type = "internal-error"
92
+
93
+ const sol = getSolution((error as IError).slug)
94
+ _err.video = sol.video
95
+ _err.gif = sol.gif
96
+ _err.message = typeof message === "string" ? message : sol.message
97
+ return _err
98
+ }
99
+
100
+ getSolution()
101
+ export default {
102
+ ValidationError,
103
+ CompilerError,
104
+ TestingError,
105
+ NotFoundError,
106
+ InternalError,
107
+ AuthError,
108
+ }