@learnpack/learnpack 2.1.30 → 2.1.31
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +12 -10
- package/lib/managers/config/index.js +2 -2
- package/lib/managers/file.js +8 -3
- package/lib/managers/server/routes.js +18 -11
- package/lib/managers/session.js +4 -14
- package/lib/models/session.d.ts +1 -2
- package/lib/utils/api.d.ts +0 -2
- package/lib/utils/api.js +19 -29
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/download.ts +0 -1
- package/src/managers/config/index.ts +2 -2
- package/src/managers/file.ts +14 -3
- package/src/managers/server/routes.ts +16 -10
- package/src/managers/session.ts +7 -13
- package/src/models/session.ts +1 -2
- package/src/utils/api.ts +20 -34
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.31 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.31/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.31/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.31/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.31/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.31/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.31/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.31/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.31/src/commands/start.ts)_
|
334
334
|
|
335
335
|
## `learnpack test [EXERCISESLUG]`
|
336
336
|
|
@@ -344,5 +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.31/src/commands/test.ts)_
|
348
348
|
<!-- commandsstop -->
|
349
|
+
|
350
|
+
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
@@ -135,9 +135,9 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
|
|
135
135
|
configObj.config.editor.version = version;
|
136
136
|
else if (configObj.config && configObj.config.editor.version === null) {
|
137
137
|
console_1.default.debug("Config version not found, downloading default.");
|
138
|
-
const resp = await fetch("https://raw.githubusercontent.com/learnpack/
|
138
|
+
const resp = await fetch("https://raw.githubusercontent.com/learnpack/ide/master/package.json");
|
139
139
|
const packageJSON = await resp.json();
|
140
|
-
configObj.config.editor.version = packageJSON.version || "
|
140
|
+
configObj.config.editor.version = packageJSON.version || "3.0.20";
|
141
141
|
}
|
142
142
|
if (configObj.config) {
|
143
143
|
configObj.config.dirPath = "./" + confPath.base;
|
package/lib/managers/file.js
CHANGED
@@ -30,9 +30,14 @@ exports.decompress = (sourcePath, destinationPath) => new Promise((resolve, reje
|
|
30
30
|
exports.downloadEditor = async (version, destination) => {
|
31
31
|
// https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
|
32
32
|
// if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
|
33
|
-
if (!version)
|
34
|
-
|
35
|
-
|
33
|
+
if (!version) {
|
34
|
+
const res = await fetch("https://raw.githubusercontent.com/learnpack/ide/master/package.json");
|
35
|
+
const json = await res.json();
|
36
|
+
version = json.version;
|
37
|
+
if (!version)
|
38
|
+
throw errors_1.InternalError(`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`);
|
39
|
+
}
|
40
|
+
const versionNumber = parseInt(version.split(".")[0]);
|
36
41
|
let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`;
|
37
42
|
if (versionNumber > 2)
|
38
43
|
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${version}.tar.gz`;
|
@@ -46,25 +46,32 @@ async function default_1(app, configObject, configManager) {
|
|
46
46
|
const payload = await session_1.default.loginWeb(email, password);
|
47
47
|
res.json(payload);
|
48
48
|
}));
|
49
|
-
app.post("/set-
|
49
|
+
app.post("/set-rigobot-token", jsonBodyParser, withHandler(async (req, res) => {
|
50
50
|
const token = req.body.token;
|
51
|
-
|
52
|
-
if (
|
53
|
-
res.json({
|
54
|
-
}
|
55
|
-
|
56
|
-
|
51
|
+
// Ensure token is provided in the request body
|
52
|
+
if (!token) {
|
53
|
+
return res.status(400).json({ error: "Token is required" });
|
54
|
+
}
|
55
|
+
try {
|
56
|
+
const tokenSaved = await session_1.default.setRigoToken(token);
|
57
|
+
// Check if the token was saved successfully
|
58
|
+
if (tokenSaved) {
|
59
|
+
res.json({ status: "ok" });
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
res.status(500).json({ error: "Failed to save the token" });
|
63
|
+
}
|
64
|
+
}
|
65
|
+
catch (_a) {
|
66
|
+
// Handle any unexpected errors during the process
|
67
|
+
res.status(500).json({ error: "Internal server error" });
|
57
68
|
}
|
58
69
|
}));
|
59
70
|
app.get("/check/rigo/status", withHandler(async (_, res) => {
|
60
71
|
const payload = await session_1.default.getPayload();
|
61
|
-
const openaiToken = await session_1.default.getOpenAIToken();
|
62
72
|
if (payload && payload.rigobot && payload.rigobot.key) {
|
63
73
|
res.json({ rigoToken: payload.rigobot.key });
|
64
74
|
}
|
65
|
-
else if (openaiToken) {
|
66
|
-
res.json({ openaiToken });
|
67
|
-
}
|
68
75
|
else {
|
69
76
|
res
|
70
77
|
.status(400)
|
package/lib/managers/session.js
CHANGED
@@ -25,21 +25,11 @@ const Session = {
|
|
25
25
|
}
|
26
26
|
return true;
|
27
27
|
},
|
28
|
-
|
28
|
+
setRigoToken: async function (token) {
|
29
29
|
await this.initialize();
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
catch (_a) {
|
35
|
-
console_1.default.debug("Error retriving openai token");
|
36
|
-
}
|
37
|
-
return token;
|
38
|
-
},
|
39
|
-
setOpenAIToken: async function (token) {
|
40
|
-
await this.initialize();
|
41
|
-
await storage.setItem("openai-token", token);
|
42
|
-
console_1.default.debug("OpenAI token successfuly set");
|
30
|
+
const payload = await storage.getItem("bc-payload");
|
31
|
+
await storage.setItem("bc-payload", Object.assign(Object.assign({}, payload), { rigobot: { key: token } }));
|
32
|
+
console_1.default.debug("Rigobot token successfuly set");
|
43
33
|
return true;
|
44
34
|
},
|
45
35
|
setPayload: async function (value) {
|
package/lib/models/session.d.ts
CHANGED
@@ -12,8 +12,7 @@ export interface ISession {
|
|
12
12
|
config: IConfig | null;
|
13
13
|
currentCohort: null;
|
14
14
|
initialize: () => Promise<boolean>;
|
15
|
-
|
16
|
-
setOpenAIToken: (token: string) => Promise<boolean>;
|
15
|
+
setRigoToken: (token: string) => Promise<boolean>;
|
17
16
|
setPayload: (value: IPayload) => Promise<boolean>;
|
18
17
|
getPayload: () => Promise<any>;
|
19
18
|
isActive: () => boolean;
|
package/lib/utils/api.d.ts
CHANGED
package/lib/utils/api.js
CHANGED
@@ -66,8 +66,14 @@ const login = async (identification, password) => {
|
|
66
66
|
method: "post",
|
67
67
|
});
|
68
68
|
cli_ux_1.default.action.stop("ready");
|
69
|
-
|
70
|
-
|
69
|
+
let rigoPayload = null;
|
70
|
+
try {
|
71
|
+
rigoPayload = await loginRigo(data.token);
|
72
|
+
}
|
73
|
+
catch (_a) {
|
74
|
+
return Object.assign(Object.assign({}, data), { rigobot: null });
|
75
|
+
}
|
76
|
+
return Object.assign(Object.assign({}, data), { rigobot: rigoPayload });
|
71
77
|
}
|
72
78
|
catch (error) {
|
73
79
|
cli_ux_1.default.action.stop("error");
|
@@ -76,31 +82,17 @@ const login = async (identification, password) => {
|
|
76
82
|
}
|
77
83
|
};
|
78
84
|
const loginRigo = async (token) => {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
current_code: Buffer.from(currentCode).toString("base64"),
|
91
|
-
tutorial: Buffer.from(readme).toString("base64"),
|
92
|
-
};
|
93
|
-
const session = await storage.getItem("bc-payload");
|
94
|
-
const response = await _fetch(`${RIGOBOT_HOST}/v1/conversation/feedback/`, {
|
95
|
-
method: "POST",
|
96
|
-
headers: {
|
97
|
-
"Content-Type": "application/json",
|
98
|
-
Authorization: `Token ${session.rigobot.key}`,
|
99
|
-
},
|
100
|
-
body: JSON.stringify(payload),
|
101
|
-
});
|
102
|
-
const responseData = await response.json();
|
103
|
-
return responseData.feedback;
|
85
|
+
try {
|
86
|
+
const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`;
|
87
|
+
const rigoResp = await _fetch(rigoUrl);
|
88
|
+
const rigobotJson = await rigoResp.json();
|
89
|
+
return rigobotJson;
|
90
|
+
}
|
91
|
+
catch (error) {
|
92
|
+
// Handle the error as needed, for example log it or return a custom error message
|
93
|
+
console_1.default.error("Error logging in to Rigo, did you already accepted Rigobot?:", error);
|
94
|
+
throw new Error("Failed to log in to Rigo");
|
95
|
+
}
|
104
96
|
};
|
105
97
|
const publish = async (config) => {
|
106
98
|
const keys = [
|
@@ -211,6 +203,4 @@ exports.default = {
|
|
211
203
|
getPackage,
|
212
204
|
getLangs,
|
213
205
|
getAllPackages,
|
214
|
-
getRigoFeedback,
|
215
|
-
getOpenAIToken,
|
216
206
|
};
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"2.1.
|
1
|
+
{"version":"2.1.31","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/download.ts
CHANGED
@@ -194,10 +194,10 @@ configObj.config.editor.version = version
|
|
194
194
|
else if (configObj.config && configObj.config.editor.version === null) {
|
195
195
|
Console.debug("Config version not found, downloading default.")
|
196
196
|
const resp = await fetch(
|
197
|
-
"https://raw.githubusercontent.com/learnpack/
|
197
|
+
"https://raw.githubusercontent.com/learnpack/ide/master/package.json"
|
198
198
|
)
|
199
199
|
const packageJSON = await resp.json()
|
200
|
-
configObj.config.editor.version = packageJSON.version || "
|
200
|
+
configObj.config.editor.version = packageJSON.version || "3.0.20"
|
201
201
|
}
|
202
202
|
|
203
203
|
if (configObj.config) {
|
package/src/managers/file.ts
CHANGED
@@ -37,9 +37,20 @@ export const downloadEditor = async (
|
|
37
37
|
// https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
|
38
38
|
// if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
|
39
39
|
|
40
|
-
if (!version)
|
41
|
-
|
42
|
-
|
40
|
+
if (!version) {
|
41
|
+
const res = await fetch(
|
42
|
+
"https://raw.githubusercontent.com/learnpack/ide/master/package.json"
|
43
|
+
)
|
44
|
+
const json = await res.json()
|
45
|
+
version = json.version
|
46
|
+
|
47
|
+
if (!version)
|
48
|
+
throw InternalError(
|
49
|
+
`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`
|
50
|
+
)
|
51
|
+
}
|
52
|
+
|
53
|
+
const versionNumber = parseInt(version.split(".")[0])
|
43
54
|
|
44
55
|
let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`
|
45
56
|
|
@@ -69,30 +69,36 @@ export default async function (
|
|
69
69
|
})
|
70
70
|
)
|
71
71
|
app.post(
|
72
|
-
"/set-
|
72
|
+
"/set-rigobot-token",
|
73
73
|
jsonBodyParser,
|
74
74
|
withHandler(async (req: express.Request, res: express.Response) => {
|
75
75
|
const token = req.body.token
|
76
|
+
// Ensure token is provided in the request body
|
77
|
+
if (!token) {
|
78
|
+
return res.status(400).json({ error: "Token is required" })
|
79
|
+
}
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
try {
|
82
|
+
const tokenSaved = await SessionManager.setRigoToken(token)
|
83
|
+
// Check if the token was saved successfully
|
84
|
+
if (tokenSaved) {
|
85
|
+
res.json({ status: "ok" })
|
86
|
+
} else {
|
87
|
+
res.status(500).json({ error: "Failed to save the token" })
|
88
|
+
}
|
89
|
+
} catch {
|
90
|
+
// Handle any unexpected errors during the process
|
91
|
+
res.status(500).json({ error: "Internal server error" })
|
82
92
|
}
|
83
93
|
})
|
84
94
|
)
|
85
|
-
|
86
95
|
app.get(
|
87
96
|
"/check/rigo/status",
|
88
97
|
withHandler(async (_: express.Request, res: express.Response) => {
|
89
98
|
const payload = await SessionManager.getPayload()
|
90
|
-
const openaiToken = await SessionManager.getOpenAIToken()
|
91
99
|
|
92
100
|
if (payload && payload.rigobot && payload.rigobot.key) {
|
93
101
|
res.json({ rigoToken: payload.rigobot.key })
|
94
|
-
} else if (openaiToken) {
|
95
|
-
res.json({ openaiToken })
|
96
102
|
} else {
|
97
103
|
res
|
98
104
|
.status(400)
|
package/src/managers/session.ts
CHANGED
@@ -32,21 +32,15 @@ const Session: ISession = {
|
|
32
32
|
|
33
33
|
return true
|
34
34
|
},
|
35
|
-
getOpenAIToken: async function () {
|
36
|
-
await this.initialize()
|
37
|
-
let token = null
|
38
|
-
try {
|
39
|
-
token = await storage.getItem("openai-token")
|
40
|
-
} catch {
|
41
|
-
Console.debug("Error retriving openai token")
|
42
|
-
}
|
43
35
|
|
44
|
-
|
45
|
-
},
|
46
|
-
setOpenAIToken: async function (token: string) {
|
36
|
+
setRigoToken: async function (token: string) {
|
47
37
|
await this.initialize()
|
48
|
-
await storage.
|
49
|
-
|
38
|
+
const payload = await storage.getItem("bc-payload")
|
39
|
+
await storage.setItem("bc-payload", {
|
40
|
+
...payload,
|
41
|
+
rigobot: { key: token },
|
42
|
+
})
|
43
|
+
Console.debug("Rigobot token successfuly set")
|
50
44
|
return true
|
51
45
|
},
|
52
46
|
setPayload: async function (value: IPayload) {
|
package/src/models/session.ts
CHANGED
@@ -15,8 +15,7 @@ export interface ISession {
|
|
15
15
|
config: IConfig | null;
|
16
16
|
currentCohort: null;
|
17
17
|
initialize: () => Promise<boolean>;
|
18
|
-
|
19
|
-
setOpenAIToken: (token: string) => Promise<boolean>;
|
18
|
+
setRigoToken: (token: string) => Promise<boolean>;
|
20
19
|
setPayload: (value: IPayload) => Promise<boolean>;
|
21
20
|
getPayload: () => Promise<any>;
|
22
21
|
isActive: () => boolean;
|
package/src/utils/api.ts
CHANGED
@@ -78,9 +78,14 @@ const login = async (identification: string, password: string) => {
|
|
78
78
|
method: "post",
|
79
79
|
})
|
80
80
|
cli.action.stop("ready")
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
let rigoPayload = null
|
82
|
+
try {
|
83
|
+
rigoPayload = await loginRigo(data.token)
|
84
|
+
} catch {
|
85
|
+
return { ...data, rigobot: null }
|
86
|
+
}
|
87
|
+
|
88
|
+
return { ...data, rigobot: rigoPayload }
|
84
89
|
} catch (error) {
|
85
90
|
cli.action.stop("error")
|
86
91
|
Console.error((error as TypeError).message)
|
@@ -89,36 +94,19 @@ const login = async (identification: string, password: string) => {
|
|
89
94
|
}
|
90
95
|
|
91
96
|
const loginRigo = async (token: string) => {
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
const payload = {
|
105
|
-
current_code: Buffer.from(currentCode).toString("base64"), // Encode currentCode as base64
|
106
|
-
tutorial: Buffer.from(readme).toString("base64"), // Encode readme as base64
|
97
|
+
try {
|
98
|
+
const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`
|
99
|
+
const rigoResp = await _fetch(rigoUrl)
|
100
|
+
const rigobotJson = await rigoResp.json()
|
101
|
+
return rigobotJson
|
102
|
+
} catch (error) {
|
103
|
+
// Handle the error as needed, for example log it or return a custom error message
|
104
|
+
Console.error(
|
105
|
+
"Error logging in to Rigo, did you already accepted Rigobot?:",
|
106
|
+
error
|
107
|
+
)
|
108
|
+
throw new Error("Failed to log in to Rigo")
|
107
109
|
}
|
108
|
-
|
109
|
-
const session = await storage.getItem("bc-payload")
|
110
|
-
|
111
|
-
const response = await _fetch(`${RIGOBOT_HOST}/v1/conversation/feedback/`, {
|
112
|
-
method: "POST",
|
113
|
-
headers: {
|
114
|
-
"Content-Type": "application/json",
|
115
|
-
Authorization: `Token ${session.rigobot.key}`,
|
116
|
-
},
|
117
|
-
body: JSON.stringify(payload),
|
118
|
-
})
|
119
|
-
|
120
|
-
const responseData = await response.json()
|
121
|
-
return responseData.feedback
|
122
110
|
}
|
123
111
|
|
124
112
|
const publish = async (config: any) => {
|
@@ -240,6 +228,4 @@ export default {
|
|
240
228
|
getPackage,
|
241
229
|
getLangs,
|
242
230
|
getAllPackages,
|
243
|
-
getRigoFeedback,
|
244
|
-
getOpenAIToken,
|
245
231
|
}
|