@learnpack/learnpack 4.0.9 → 4.0.12

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 (128) hide show
  1. package/README.md +25 -10
  2. package/lib/commands/audit.d.ts +6 -6
  3. package/lib/commands/audit.js +327 -327
  4. package/lib/commands/build.d.ts +11 -0
  5. package/lib/commands/build.js +160 -0
  6. package/lib/commands/clean.d.ts +8 -8
  7. package/lib/commands/clean.js +22 -22
  8. package/lib/commands/download.d.ts +13 -13
  9. package/lib/commands/download.js +52 -52
  10. package/lib/commands/init.d.ts +9 -9
  11. package/lib/commands/init.js +127 -127
  12. package/lib/commands/login.d.ts +14 -14
  13. package/lib/commands/login.js +34 -34
  14. package/lib/commands/logout.d.ts +14 -14
  15. package/lib/commands/logout.js +34 -34
  16. package/lib/commands/publish.d.ts +14 -14
  17. package/lib/commands/publish.js +79 -79
  18. package/lib/commands/start.d.ts +7 -7
  19. package/lib/commands/start.js +252 -250
  20. package/lib/commands/test.d.ts +6 -6
  21. package/lib/commands/test.js +62 -62
  22. package/lib/index.d.ts +1 -1
  23. package/lib/index.js +4 -4
  24. package/lib/managers/config/allowed_files.d.ts +5 -5
  25. package/lib/managers/config/allowed_files.js +30 -30
  26. package/lib/managers/config/defaults.d.ts +47 -48
  27. package/lib/managers/config/defaults.js +51 -51
  28. package/lib/managers/config/exercise.d.ts +36 -36
  29. package/lib/managers/config/exercise.js +243 -236
  30. package/lib/managers/config/index.d.ts +3 -3
  31. package/lib/managers/config/index.js +464 -459
  32. package/lib/managers/file.d.ts +14 -14
  33. package/lib/managers/file.js +190 -184
  34. package/lib/managers/gitpod.d.ts +3 -3
  35. package/lib/managers/gitpod.js +67 -67
  36. package/lib/managers/server/index.d.ts +5 -6
  37. package/lib/managers/server/index.js +58 -58
  38. package/lib/managers/server/routes.d.ts +4 -4
  39. package/lib/managers/server/routes.js +228 -220
  40. package/lib/managers/session.d.ts +3 -3
  41. package/lib/managers/session.js +125 -125
  42. package/lib/managers/socket.d.ts +3 -3
  43. package/lib/managers/socket.js +188 -186
  44. package/lib/managers/telemetry.d.ts +74 -74
  45. package/lib/managers/telemetry.js +215 -214
  46. package/lib/managers/test.js +84 -84
  47. package/lib/models/action.d.ts +2 -2
  48. package/lib/models/action.js +2 -2
  49. package/lib/models/audit.d.ts +15 -15
  50. package/lib/models/audit.js +2 -2
  51. package/lib/models/config-manager.d.ts +21 -21
  52. package/lib/models/config-manager.js +2 -2
  53. package/lib/models/config.d.ts +86 -86
  54. package/lib/models/config.js +2 -2
  55. package/lib/models/counter.d.ts +11 -11
  56. package/lib/models/counter.js +2 -2
  57. package/lib/models/errors.d.ts +15 -15
  58. package/lib/models/errors.js +2 -2
  59. package/lib/models/exercise-obj.d.ts +29 -30
  60. package/lib/models/exercise-obj.js +2 -2
  61. package/lib/models/file.d.ts +5 -5
  62. package/lib/models/file.js +2 -2
  63. package/lib/models/findings.d.ts +17 -17
  64. package/lib/models/findings.js +2 -2
  65. package/lib/models/flags.d.ts +10 -10
  66. package/lib/models/flags.js +2 -2
  67. package/lib/models/front-matter.d.ts +11 -11
  68. package/lib/models/front-matter.js +2 -2
  69. package/lib/models/gitpod-data.d.ts +16 -16
  70. package/lib/models/gitpod-data.js +2 -2
  71. package/lib/models/language.d.ts +4 -4
  72. package/lib/models/language.js +2 -2
  73. package/lib/models/package.d.ts +7 -7
  74. package/lib/models/package.js +2 -2
  75. package/lib/models/plugin-config.d.ts +16 -16
  76. package/lib/models/plugin-config.js +2 -2
  77. package/lib/models/session.d.ts +31 -31
  78. package/lib/models/session.js +2 -2
  79. package/lib/models/socket.d.ts +37 -37
  80. package/lib/models/socket.js +2 -2
  81. package/lib/models/status.d.ts +1 -1
  82. package/lib/models/status.js +2 -2
  83. package/lib/models/success-types.d.ts +1 -1
  84. package/lib/models/success-types.js +2 -2
  85. package/lib/plugin/command/compile.d.ts +6 -6
  86. package/lib/plugin/command/compile.js +18 -18
  87. package/lib/plugin/command/test.d.ts +6 -6
  88. package/lib/plugin/command/test.js +25 -25
  89. package/lib/plugin/index.d.ts +27 -27
  90. package/lib/plugin/index.js +7 -7
  91. package/lib/plugin/plugin.d.ts +8 -8
  92. package/lib/plugin/plugin.js +68 -68
  93. package/lib/plugin/utils.d.ts +16 -16
  94. package/lib/plugin/utils.js +58 -58
  95. package/lib/ui/download.d.ts +5 -5
  96. package/lib/ui/download.js +62 -61
  97. package/lib/utils/BaseCommand.d.ts +8 -8
  98. package/lib/utils/BaseCommand.js +41 -41
  99. package/lib/utils/SessionCommand.d.ts +10 -10
  100. package/lib/utils/SessionCommand.js +43 -43
  101. package/lib/utils/api.d.ts +14 -14
  102. package/lib/utils/api.js +255 -255
  103. package/lib/utils/audit.d.ts +16 -16
  104. package/lib/utils/audit.js +303 -303
  105. package/lib/utils/checkNotInstalled.d.ts +8 -8
  106. package/lib/utils/checkNotInstalled.js +185 -181
  107. package/lib/utils/console.d.ts +12 -12
  108. package/lib/utils/console.js +19 -19
  109. package/lib/utils/errors.d.ts +17 -17
  110. package/lib/utils/errors.js +107 -100
  111. package/lib/utils/exercisesQueue.d.ts +9 -9
  112. package/lib/utils/exercisesQueue.js +38 -38
  113. package/lib/utils/fileQueue.d.ts +43 -43
  114. package/lib/utils/fileQueue.js +169 -169
  115. package/lib/utils/misc.d.ts +1 -1
  116. package/lib/utils/misc.js +24 -23
  117. package/lib/utils/osOperations.d.ts +5 -5
  118. package/lib/utils/osOperations.js +72 -72
  119. package/lib/utils/validators.d.ts +5 -5
  120. package/lib/utils/validators.js +16 -17
  121. package/lib/utils/watcher.d.ts +2 -2
  122. package/lib/utils/watcher.js +25 -25
  123. package/oclif.manifest.json +1 -1
  124. package/package.json +6 -4
  125. package/src/commands/build.ts +181 -0
  126. package/src/managers/config/index.ts +5 -0
  127. package/src/managers/server/routes.ts +11 -1
  128. package/src/managers/session.ts +1 -1
@@ -1,14 +1,14 @@
1
- declare const _default: {
2
- login: (identification: string, password: string) => Promise<any>;
3
- publish: (config: any) => Promise<any>;
4
- update: (config: any) => Promise<any>;
5
- getPackage: (slug: string) => Promise<any>;
6
- getLangs: () => Promise<any>;
7
- getAllPackages: ({ lang, slug, }: {
8
- lang?: string | undefined;
9
- slug?: string | undefined;
10
- }) => Promise<any>;
11
- sendBatchTelemetry: (url: string, body: object) => Promise<void>;
12
- sendStreamTelemetry: (url: string, body: object) => Promise<void>;
13
- };
14
- export default _default;
1
+ declare const _default: {
2
+ login: (identification: string, password: string) => Promise<any>;
3
+ publish: (config: any) => Promise<any>;
4
+ update: (config: any) => Promise<any>;
5
+ getPackage: (slug: string) => Promise<any>;
6
+ getLangs: () => Promise<any>;
7
+ getAllPackages: ({ lang, slug, }: {
8
+ lang?: string;
9
+ slug?: string;
10
+ }) => Promise<any>;
11
+ sendBatchTelemetry: (url: string, body: object) => Promise<void>;
12
+ sendStreamTelemetry: (url: string, body: object) => Promise<void>;
13
+ };
14
+ export default _default;
package/lib/utils/api.js CHANGED
@@ -1,255 +1,255 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const console_1 = require("../utils/console");
4
- const storage = require("node-persist");
5
- const cli_ux_1 = require("cli-ux");
6
- const HOST = "https://breathecode.herokuapp.com";
7
- const RIGOBOT_HOST = "https://rigobot.herokuapp.com";
8
- // eslint-disable-next-line
9
- const _fetch = require("node-fetch");
10
- const fetch = async (url, options = {}, returnAsJson = true) => {
11
- const headers = { "Content-Type": "application/json" };
12
- console_1.default.debug(`Fetching ${url}`);
13
- let session = null;
14
- try {
15
- session = await storage.getItem("bc-payload");
16
- if (session.token && session.token !== "" && !url.includes("/token"))
17
- headers.Authorization = "Token " + session.token;
18
- }
19
- catch (_a) { }
20
- try {
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 returnAsJson ? await resp.json() : await resp.text();
24
- }
25
- if (resp.status === 401)
26
- console_1.default.debug("Invalid authentication credentials", `Code: 401`);
27
- // throw APIError("Invalid authentication credentials", 401)
28
- else if (resp.status === 404)
29
- throw APIError("Package not found", 404);
30
- else if (resp.status >= 500)
31
- throw APIError("Impossible to connect with the server", 500);
32
- else if (resp.status >= 400) {
33
- const error = await resp.json();
34
- if (error.detail || error.error) {
35
- throw APIError(error.detail || error.error);
36
- }
37
- else if (error.nonFieldErrors) {
38
- throw APIError(error.nonFieldErrors[0], error);
39
- }
40
- else if (typeof error === "object") {
41
- if (Object.keys(error).length > 0) {
42
- const key = error[Object.keys(error)[0]];
43
- throw APIError(`${key}: ${error[key][0]}`, error);
44
- }
45
- }
46
- else {
47
- throw APIError("Uknown error");
48
- }
49
- }
50
- else
51
- throw APIError("Uknown error");
52
- }
53
- catch (error) {
54
- console_1.default.error(error.message);
55
- throw error;
56
- }
57
- };
58
- const login = async (identification, password) => {
59
- try {
60
- cli_ux_1.default.action.start(`Looking for credentials with ${identification}`);
61
- await cli_ux_1.default.wait(1000);
62
- const url = `${HOST}/v1/auth/login/`;
63
- const data = await fetch(url, {
64
- body: JSON.stringify({
65
- email: identification,
66
- password: password,
67
- }),
68
- method: "post",
69
- });
70
- cli_ux_1.default.action.stop("ready");
71
- let rigoPayload = null;
72
- try {
73
- rigoPayload = await loginRigo(data.token);
74
- }
75
- catch (_a) {
76
- return Object.assign(Object.assign({}, data), { rigobot: null });
77
- }
78
- return Object.assign(Object.assign({}, data), { rigobot: rigoPayload });
79
- }
80
- catch (error) {
81
- cli_ux_1.default.action.stop("error");
82
- console_1.default.error(error.message);
83
- console_1.default.debug(error);
84
- }
85
- };
86
- const loginRigo = async (token) => {
87
- try {
88
- const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`;
89
- const rigoResp = await _fetch(rigoUrl);
90
- const rigobotJson = await rigoResp.json();
91
- return rigobotJson;
92
- }
93
- catch (error) {
94
- // Handle the error as needed, for example log it or return a custom error message
95
- console_1.default.error("Error logging in to Rigo, did you already accepted Rigobot?:", error);
96
- throw new Error("Failed to log in to Rigo");
97
- }
98
- };
99
- const publish = async (config) => {
100
- const keys = [
101
- "difficulty",
102
- "language",
103
- "skills",
104
- "technologies",
105
- "slug",
106
- "repository",
107
- "author",
108
- "title",
109
- ];
110
- const payload = {};
111
- for (const k of keys)
112
- config[k] ? (payload[k] = config[k]) : null;
113
- try {
114
- console.log("Package to publish:", payload);
115
- cli_ux_1.default.action.start("Updating package information...");
116
- await cli_ux_1.default.wait(1000);
117
- const data = await fetch(`${HOST}/v1/package/${config.slug}`, {
118
- method: "PUT",
119
- body: JSON.stringify(payload),
120
- });
121
- cli_ux_1.default.action.stop("ready");
122
- return data;
123
- }
124
- catch (error) {
125
- console_1.default.error(error.message);
126
- console_1.default.debug(error);
127
- throw error;
128
- }
129
- };
130
- const update = async (config) => {
131
- try {
132
- cli_ux_1.default.action.start("Updating package information...");
133
- await cli_ux_1.default.wait(1000);
134
- const data = await fetch(`${HOST}/v1/package/`, {
135
- method: "POST",
136
- body: JSON.stringify(config),
137
- });
138
- cli_ux_1.default.action.stop("ready");
139
- return data;
140
- }
141
- catch (error) {
142
- console_1.default.error(error.message);
143
- console_1.default.debug(error);
144
- throw error;
145
- }
146
- };
147
- const getPackage = async (slug) => {
148
- try {
149
- cli_ux_1.default.action.start("Downloading package information...");
150
- await cli_ux_1.default.wait(1000);
151
- const data = await fetch(`${HOST}/v1/package/${slug}`);
152
- cli_ux_1.default.action.stop("ready");
153
- return data;
154
- }
155
- catch (error) {
156
- if (error.status === 404)
157
- console_1.default.error(`Package ${slug} does not exist`);
158
- else
159
- console_1.default.error(`Package ${slug} does not exist`);
160
- console_1.default.debug(error);
161
- throw error;
162
- }
163
- };
164
- const getLangs = async () => {
165
- try {
166
- cli_ux_1.default.action.start("Downloading language options...");
167
- await cli_ux_1.default.wait(1000);
168
- const data = await fetch(`${HOST}/v1/package/language`);
169
- cli_ux_1.default.action.stop("ready");
170
- return data;
171
- }
172
- catch (error) {
173
- if (error.status === 404)
174
- console_1.default.error("Package slug does not exist");
175
- else
176
- console_1.default.error("Package slug does not exist");
177
- console_1.default.debug(error);
178
- throw error;
179
- }
180
- };
181
- const getAllPackages = async ({ lang = "", slug = "", }) => {
182
- try {
183
- cli_ux_1.default.action.start("Downloading packages...");
184
- await cli_ux_1.default.wait(1000);
185
- const data = await fetch(`${HOST}/v1/package/all?limit=100&language=${lang}&slug=${slug}`);
186
- cli_ux_1.default.action.stop("ready");
187
- return data;
188
- }
189
- catch (error) {
190
- console_1.default.error(`Package ${slug} does not exist`);
191
- console_1.default.debug(error);
192
- throw error;
193
- }
194
- };
195
- const APIError = (error, code) => {
196
- const message = error.message || error;
197
- const _err = new Error(message);
198
- _err.status = code || 400;
199
- return _err;
200
- };
201
- const sendBatchTelemetry = async function (url, body) {
202
- if (!url) {
203
- return;
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
- }
212
- fetch(url, {
213
- method: "POST",
214
- body: JSON.stringify(body),
215
- }, false)
216
- .then(response => {
217
- console_1.default.debug("Telemetry sent successfully");
218
- return response.text();
219
- })
220
- .catch(error => {
221
- console_1.default.debug("Error while sending batch Telemetry", error);
222
- });
223
- };
224
- const sendStreamTelemetry = async function (url, body) {
225
- if (!url) {
226
- return;
227
- }
228
- const session = await storage.getItem("bc-payload");
229
- if (!session ||
230
- !Object.prototype.hasOwnProperty.call(session, "token") ||
231
- session.token === "") {
232
- console_1.default.debug("No token found, skipping stream telemetry delivery");
233
- return;
234
- }
235
- fetch(url, {
236
- method: "POST",
237
- body: JSON.stringify(body),
238
- }, false)
239
- .then(response => {
240
- return response;
241
- })
242
- .catch(error => {
243
- console_1.default.debug("Error while sending stream Telemetry", error);
244
- });
245
- };
246
- exports.default = {
247
- login,
248
- publish,
249
- update,
250
- getPackage,
251
- getLangs,
252
- getAllPackages,
253
- sendBatchTelemetry,
254
- sendStreamTelemetry,
255
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const console_1 = require("../utils/console");
4
+ const storage = require("node-persist");
5
+ const cli_ux_1 = require("cli-ux");
6
+ const HOST = "https://breathecode.herokuapp.com";
7
+ const RIGOBOT_HOST = "https://rigobot.herokuapp.com";
8
+ // eslint-disable-next-line
9
+ const _fetch = require("node-fetch");
10
+ const fetch = async (url, options = {}, returnAsJson = true) => {
11
+ const headers = { "Content-Type": "application/json" };
12
+ console_1.default.debug(`Fetching ${url}`);
13
+ let session = null;
14
+ try {
15
+ session = await storage.getItem("bc-payload");
16
+ if (session.token && session.token !== "" && !url.includes("/token"))
17
+ headers.Authorization = "Token " + session.token;
18
+ }
19
+ catch (_a) { }
20
+ try {
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 returnAsJson ? await resp.json() : await resp.text();
24
+ }
25
+ if (resp.status === 401)
26
+ console_1.default.debug("Invalid authentication credentials", `Code: 401`);
27
+ // throw APIError("Invalid authentication credentials", 401)
28
+ else if (resp.status === 404)
29
+ throw APIError("Package not found", 404);
30
+ else if (resp.status >= 500)
31
+ throw APIError("Impossible to connect with the server", 500);
32
+ else if (resp.status >= 400) {
33
+ const error = await resp.json();
34
+ if (error.detail || error.error) {
35
+ throw APIError(error.detail || error.error);
36
+ }
37
+ else if (error.nonFieldErrors) {
38
+ throw APIError(error.nonFieldErrors[0], error);
39
+ }
40
+ else if (typeof error === "object") {
41
+ if (Object.keys(error).length > 0) {
42
+ const key = error[Object.keys(error)[0]];
43
+ throw APIError(`${key}: ${error[key][0]}`, error);
44
+ }
45
+ }
46
+ else {
47
+ throw APIError("Uknown error");
48
+ }
49
+ }
50
+ else
51
+ throw APIError("Uknown error");
52
+ }
53
+ catch (error) {
54
+ console_1.default.error(error.message);
55
+ throw error;
56
+ }
57
+ };
58
+ const login = async (identification, password) => {
59
+ try {
60
+ cli_ux_1.default.action.start(`Looking for credentials with ${identification}`);
61
+ await cli_ux_1.default.wait(1000);
62
+ const url = `${HOST}/v1/auth/login/`;
63
+ const data = await fetch(url, {
64
+ body: JSON.stringify({
65
+ email: identification,
66
+ password: password,
67
+ }),
68
+ method: "post",
69
+ });
70
+ cli_ux_1.default.action.stop("ready");
71
+ let rigoPayload = null;
72
+ try {
73
+ rigoPayload = await loginRigo(data.token);
74
+ }
75
+ catch (_a) {
76
+ return Object.assign(Object.assign({}, data), { rigobot: null });
77
+ }
78
+ return Object.assign(Object.assign({}, data), { rigobot: rigoPayload });
79
+ }
80
+ catch (error) {
81
+ cli_ux_1.default.action.stop("error");
82
+ console_1.default.error(error.message);
83
+ console_1.default.debug(error);
84
+ }
85
+ };
86
+ const loginRigo = async (token) => {
87
+ try {
88
+ const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`;
89
+ const rigoResp = await _fetch(rigoUrl);
90
+ const rigobotJson = await rigoResp.json();
91
+ return rigobotJson;
92
+ }
93
+ catch (error) {
94
+ // Handle the error as needed, for example log it or return a custom error message
95
+ console_1.default.error("Error logging in to Rigo, did you already accepted Rigobot?:", error);
96
+ throw new Error("Failed to log in to Rigo");
97
+ }
98
+ };
99
+ const publish = async (config) => {
100
+ const keys = [
101
+ "difficulty",
102
+ "language",
103
+ "skills",
104
+ "technologies",
105
+ "slug",
106
+ "repository",
107
+ "author",
108
+ "title",
109
+ ];
110
+ const payload = {};
111
+ for (const k of keys)
112
+ config[k] ? (payload[k] = config[k]) : null;
113
+ try {
114
+ console.log("Package to publish:", payload);
115
+ cli_ux_1.default.action.start("Updating package information...");
116
+ await cli_ux_1.default.wait(1000);
117
+ const data = await fetch(`${HOST}/v1/package/${config.slug}`, {
118
+ method: "PUT",
119
+ body: JSON.stringify(payload),
120
+ });
121
+ cli_ux_1.default.action.stop("ready");
122
+ return data;
123
+ }
124
+ catch (error) {
125
+ console_1.default.error(error.message);
126
+ console_1.default.debug(error);
127
+ throw error;
128
+ }
129
+ };
130
+ const update = async (config) => {
131
+ try {
132
+ cli_ux_1.default.action.start("Updating package information...");
133
+ await cli_ux_1.default.wait(1000);
134
+ const data = await fetch(`${HOST}/v1/package/`, {
135
+ method: "POST",
136
+ body: JSON.stringify(config),
137
+ });
138
+ cli_ux_1.default.action.stop("ready");
139
+ return data;
140
+ }
141
+ catch (error) {
142
+ console_1.default.error(error.message);
143
+ console_1.default.debug(error);
144
+ throw error;
145
+ }
146
+ };
147
+ const getPackage = async (slug) => {
148
+ try {
149
+ cli_ux_1.default.action.start("Downloading package information...");
150
+ await cli_ux_1.default.wait(1000);
151
+ const data = await fetch(`${HOST}/v1/package/${slug}`);
152
+ cli_ux_1.default.action.stop("ready");
153
+ return data;
154
+ }
155
+ catch (error) {
156
+ if (error.status === 404)
157
+ console_1.default.error(`Package ${slug} does not exist`);
158
+ else
159
+ console_1.default.error(`Package ${slug} does not exist`);
160
+ console_1.default.debug(error);
161
+ throw error;
162
+ }
163
+ };
164
+ const getLangs = async () => {
165
+ try {
166
+ cli_ux_1.default.action.start("Downloading language options...");
167
+ await cli_ux_1.default.wait(1000);
168
+ const data = await fetch(`${HOST}/v1/package/language`);
169
+ cli_ux_1.default.action.stop("ready");
170
+ return data;
171
+ }
172
+ catch (error) {
173
+ if (error.status === 404)
174
+ console_1.default.error("Package slug does not exist");
175
+ else
176
+ console_1.default.error("Package slug does not exist");
177
+ console_1.default.debug(error);
178
+ throw error;
179
+ }
180
+ };
181
+ const getAllPackages = async ({ lang = "", slug = "", }) => {
182
+ try {
183
+ cli_ux_1.default.action.start("Downloading packages...");
184
+ await cli_ux_1.default.wait(1000);
185
+ const data = await fetch(`${HOST}/v1/package/all?limit=100&language=${lang}&slug=${slug}`);
186
+ cli_ux_1.default.action.stop("ready");
187
+ return data;
188
+ }
189
+ catch (error) {
190
+ console_1.default.error(`Package ${slug} does not exist`);
191
+ console_1.default.debug(error);
192
+ throw error;
193
+ }
194
+ };
195
+ const APIError = (error, code) => {
196
+ const message = error.message || error;
197
+ const _err = new Error(message);
198
+ _err.status = code || 400;
199
+ return _err;
200
+ };
201
+ const sendBatchTelemetry = async function (url, body) {
202
+ if (!url) {
203
+ return;
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
+ }
212
+ fetch(url, {
213
+ method: "POST",
214
+ body: JSON.stringify(body),
215
+ }, false)
216
+ .then(response => {
217
+ console_1.default.debug("Telemetry sent successfully");
218
+ return response.text();
219
+ })
220
+ .catch(error => {
221
+ console_1.default.debug("Error while sending batch Telemetry", error);
222
+ });
223
+ };
224
+ const sendStreamTelemetry = async function (url, body) {
225
+ if (!url) {
226
+ return;
227
+ }
228
+ const session = await storage.getItem("bc-payload");
229
+ if (!session ||
230
+ !Object.prototype.hasOwnProperty.call(session, "token") ||
231
+ session.token === "") {
232
+ console_1.default.debug("No token found, skipping stream telemetry delivery");
233
+ return;
234
+ }
235
+ fetch(url, {
236
+ method: "POST",
237
+ body: JSON.stringify(body),
238
+ }, false)
239
+ .then(response => {
240
+ return response;
241
+ })
242
+ .catch(error => {
243
+ console_1.default.debug("Error while sending stream Telemetry", error);
244
+ });
245
+ };
246
+ exports.default = {
247
+ login,
248
+ publish,
249
+ update,
250
+ getPackage,
251
+ getLangs,
252
+ getAllPackages,
253
+ sendBatchTelemetry,
254
+ sendStreamTelemetry,
255
+ };
@@ -1,16 +1,16 @@
1
- import { IAuditErrors } from "../models/audit";
2
- import { IConfigObj } from "../models/config";
3
- import { ICounter } from "../models/counter";
4
- import { IFindings } from "../models/findings";
5
- import { IExercise } from "../models/exercise-obj";
6
- declare const _default: {
7
- isUrl: (url: string, errors: IAuditErrors[], counter: ICounter) => Promise<boolean>;
8
- checkForEmptySpaces: (str: string) => boolean;
9
- checkLearnpackClean: (configObj: IConfigObj, errors: IAuditErrors[]) => void;
10
- findInFile: (types: string[], content: string) => IFindings;
11
- checkUrl: (config: IConfigObj, filePath: string, fileName: string, exercise: IExercise | undefined, errors: IAuditErrors[], warnings: IAuditErrors[], counter: ICounter | undefined) => Promise<boolean>;
12
- writeFile: (content: string, filePath: string) => Promise<void>;
13
- showErrors: (errors: IAuditErrors[], counter: ICounter | undefined) => Promise<unknown>;
14
- showWarnings: (warnings: IAuditErrors[]) => Promise<unknown>;
15
- };
16
- export default _default;
1
+ import { IAuditErrors } from "../models/audit";
2
+ import { IConfigObj } from "../models/config";
3
+ import { ICounter } from "../models/counter";
4
+ import { IFindings } from "../models/findings";
5
+ import { IExercise } from "../models/exercise-obj";
6
+ declare const _default: {
7
+ isUrl: (url: string, errors: IAuditErrors[], counter: ICounter) => Promise<boolean>;
8
+ checkForEmptySpaces: (str: string) => boolean;
9
+ checkLearnpackClean: (configObj: IConfigObj, errors: IAuditErrors[]) => void;
10
+ findInFile: (types: string[], content: string) => IFindings;
11
+ checkUrl: (config: IConfigObj, filePath: string, fileName: string, exercise: IExercise | undefined, errors: IAuditErrors[], warnings: IAuditErrors[], counter: ICounter | undefined) => Promise<boolean>;
12
+ writeFile: (content: string, filePath: string) => Promise<void>;
13
+ showErrors: (errors: IAuditErrors[], counter: ICounter | undefined) => Promise<unknown>;
14
+ showWarnings: (warnings: IAuditErrors[]) => Promise<unknown>;
15
+ };
16
+ export default _default;