@learnpack/learnpack 5.0.284 → 5.0.286

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.
@@ -10,7 +10,7 @@
10
10
  />
11
11
 
12
12
  <title>Learnpack Creator: Craft tutorials in seconds!</title>
13
- <script type="module" crossorigin src="/creator/assets/index-7zTdUX04.js"></script>
13
+ <script type="module" crossorigin src="/creator/assets/index-CQMtxRqZ.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/creator/assets/index-C39zeF3W.css">
15
15
  </head>
16
16
  <body>
@@ -1,182 +1,184 @@
1
- import Console from "../utils/console"
2
- import api from "../utils/api"
3
-
4
- import v from "validator"
5
- import { ValidationError, InternalError } from "../utils/errors"
6
-
7
- import * as fs from "fs"
8
- import cli from "cli-ux"
9
- import * as storage from "node-persist"
10
-
11
- import { IPayload, ISession, IStartProps } from "../models/session"
12
- import { IConfigObj } from "../models/config"
13
- import TelemetryManager from "./telemetry"
14
- import * as path from "path"
15
- import * as os from "os"
16
-
17
- const GLOBAL_SESSION_PATH = path.join(os.homedir(), ".learnpack-session")
18
-
19
- const Session: ISession = {
20
- sessionStarted: false,
21
- token: null,
22
- config: null,
23
- currentCohort: null,
24
- initialize: async function () {
25
- if (!this.sessionStarted) {
26
- // Use a system-wide path instead of config.dirPath
27
- if (!fs.existsSync(GLOBAL_SESSION_PATH)) {
28
- fs.mkdirSync(GLOBAL_SESSION_PATH, { recursive: true })
29
- }
30
-
31
- await storage.init({ dir: GLOBAL_SESSION_PATH })
32
- this.sessionStarted = true
33
- }
34
-
35
- return true
36
- },
37
-
38
- setRigoToken: async function (token: string) {
39
- await this.initialize()
40
- const payload = await storage.getItem("bc-payload")
41
- await storage.setItem("bc-payload", {
42
- ...payload,
43
- rigobot: { key: token },
44
- })
45
- Console.debug("Rigobot token successfuly set")
46
- return true
47
- },
48
- setTabHash: async function (hash: string) {
49
- await this.initialize()
50
- const payload = await storage.getItem("bc-payload")
51
- await storage.setItem("bc-payload", {
52
- ...payload,
53
- tabHash: hash,
54
- })
55
- Console.debug("tabHash successfuly set")
56
- return true
57
- },
58
- setSessionKey: async function (value: string) {
59
- await this.initialize()
60
- const payload = await storage.getItem("bc-payload")
61
- await storage.setItem("bc-payload", {
62
- ...payload,
63
- sessionKey: value,
64
- })
65
- Console.debug("sessionKey successfuly set")
66
- return true
67
- },
68
- setPayload: async function (value: IPayload) {
69
- await this.initialize()
70
- await storage.setItem("bc-payload", { ...value })
71
- Console.debug("Payload successfuly found and set for " + value.email)
72
-
73
- // TelemetryManager.setStudent({
74
- // user_id: value.user_id.toString(),
75
- // email: value.email,
76
- // token: value.token,
77
- // })
78
-
79
- return true
80
- },
81
- getPayload: async function () {
82
- await this.initialize()
83
- let payload = null
84
- try {
85
- payload = await storage.getItem("bc-payload")
86
- } catch {
87
- Console.debug("Error retriving session payload")
88
- }
89
-
90
- return payload
91
- },
92
- isActive: function () {
93
- return !!this.token
94
- },
95
- get: async function (configObj?: IConfigObj) {
96
- if (configObj && configObj.config) {
97
- this.config = configObj.config
98
- }
99
-
100
- await this.sync()
101
- if (!this.isActive()) {
102
- return null
103
- }
104
-
105
- const payload = await this.getPayload()
106
-
107
- return {
108
- payload,
109
- token: this.token,
110
- }
111
- },
112
- login: async function () {
113
- const email = await cli.prompt("What is your email?")
114
- if (!v.isEmail(email)) {
115
- throw ValidationError("Invalid email")
116
- }
117
-
118
- const password = await cli.prompt("What is your password?", {
119
- type: "hide",
120
- })
121
-
122
- const data = await api.login(email, password)
123
-
124
- if (data) {
125
- Console.debug("Login successfull")
126
- // cli.log(data)
127
- await this.start({ token: data.token, payload: data })
128
- return data
129
- }
130
- },
131
- loginWeb: async function (email, password) {
132
- if (!v.isEmail(email)) {
133
- throw ValidationError("Invalid email")
134
- }
135
-
136
- const data = await api.login(email, password)
137
- if (data) {
138
- this.start({ token: data.token, payload: data })
139
-
140
- return data
141
- }
142
- },
143
- sync: async function () {
144
- const payload = await this.getPayload()
145
- if (payload) {
146
- this.token = payload.token
147
- }
148
- },
149
- start: async function ({ token, payload = null }: IStartProps) {
150
- if (!token) {
151
- throw new Error("A token and email is needed to start a session")
152
- }
153
-
154
- this.token = token
155
-
156
- if (payload && (await this.setPayload(payload))) {
157
- Console.success(`Successfully logged in as ${payload.email}`)
158
- }
159
- },
160
- destroy: async function () {
161
- if (!this.sessionStarted) {
162
- await this.initialize()
163
- }
164
-
165
- await storage.clear()
166
- this.token = null
167
- Console.success("You have logged out")
168
- },
169
- breakToken: async function () {
170
- const payload = await this.getPayload()
171
- if (payload) {
172
- this.token = "asdasdasdasd"
173
- await storage.setItem("bc-payload", {
174
- ...payload,
175
- token: "asdasdsad",
176
- })
177
- Console.success("Token broken successfully")
178
- }
179
- },
180
- }
181
-
182
- export default Session
1
+ import Console from "../utils/console"
2
+ import api from "../utils/api"
3
+
4
+ import v from "validator"
5
+ import { ValidationError, InternalError } from "../utils/errors"
6
+
7
+ import * as fs from "fs"
8
+ import cli from "cli-ux"
9
+ import * as storage from "node-persist"
10
+
11
+ import { IPayload, ISession, IStartProps } from "../models/session"
12
+ import { IConfigObj } from "../models/config"
13
+ import TelemetryManager from "./telemetry"
14
+ import * as path from "path"
15
+ import * as os from "os"
16
+
17
+ const GLOBAL_SESSION_PATH = path.join(os.homedir(), ".learnpack-session")
18
+
19
+ const Session: ISession = {
20
+ sessionStarted: false,
21
+ token: null,
22
+ config: null,
23
+ currentCohort: null,
24
+ initialize: async function () {
25
+ if (!this.sessionStarted) {
26
+ // Use a system-wide path instead of config.dirPath
27
+ if (!fs.existsSync(GLOBAL_SESSION_PATH)) {
28
+ fs.mkdirSync(GLOBAL_SESSION_PATH, { recursive: true })
29
+ }
30
+
31
+ await storage.init({ dir: GLOBAL_SESSION_PATH })
32
+ this.sessionStarted = true
33
+ }
34
+
35
+ return true
36
+ },
37
+
38
+ setRigoToken: async function (token: string) {
39
+ await this.initialize()
40
+ const payload = await storage.getItem("bc-payload")
41
+ await storage.setItem("bc-payload", {
42
+ ...payload,
43
+ rigobot: { key: token },
44
+ })
45
+ Console.debug("Rigobot token successfuly set")
46
+ return true
47
+ },
48
+ setTabHash: async function (hash: string) {
49
+ await this.initialize()
50
+ const payload = await storage.getItem("bc-payload")
51
+ await storage.setItem("bc-payload", {
52
+ ...payload,
53
+ tabHash: hash,
54
+ })
55
+ Console.debug("tabHash successfuly set")
56
+ return true
57
+ },
58
+ setSessionKey: async function (value: string) {
59
+ await this.initialize()
60
+ const payload = await storage.getItem("bc-payload")
61
+ await storage.setItem("bc-payload", {
62
+ ...payload,
63
+ sessionKey: value,
64
+ })
65
+ Console.debug("sessionKey successfuly set")
66
+ return true
67
+ },
68
+ setPayload: async function (value: IPayload) {
69
+ await this.initialize()
70
+ await storage.setItem("bc-payload", { ...value })
71
+ Console.debug(
72
+ "Payload successfuly found and set for user " + value.user_id
73
+ )
74
+
75
+ // TelemetryManager.setStudent({
76
+ // user_id: value.user_id.toString(),
77
+ // email: value.email,
78
+ // token: value.token,
79
+ // })
80
+
81
+ return true
82
+ },
83
+ getPayload: async function () {
84
+ await this.initialize()
85
+ let payload = null
86
+ try {
87
+ payload = await storage.getItem("bc-payload")
88
+ } catch {
89
+ Console.debug("Error retriving session payload")
90
+ }
91
+
92
+ return payload
93
+ },
94
+ isActive: function () {
95
+ return !!this.token
96
+ },
97
+ get: async function (configObj?: IConfigObj) {
98
+ if (configObj && configObj.config) {
99
+ this.config = configObj.config
100
+ }
101
+
102
+ await this.sync()
103
+ if (!this.isActive()) {
104
+ return null
105
+ }
106
+
107
+ const payload = await this.getPayload()
108
+
109
+ return {
110
+ payload,
111
+ token: this.token,
112
+ }
113
+ },
114
+ login: async function () {
115
+ const email = await cli.prompt("What is your email?")
116
+ if (!v.isEmail(email)) {
117
+ throw ValidationError("Invalid email")
118
+ }
119
+
120
+ const password = await cli.prompt("What is your password?", {
121
+ type: "hide",
122
+ })
123
+
124
+ const data = await api.login(email, password)
125
+
126
+ if (data) {
127
+ Console.debug("Login successfull")
128
+ // cli.log(data)
129
+ await this.start({ token: data.token, payload: data })
130
+ return data
131
+ }
132
+ },
133
+ loginWeb: async function (email, password) {
134
+ if (!v.isEmail(email)) {
135
+ throw ValidationError("Invalid email")
136
+ }
137
+
138
+ const data = await api.login(email, password)
139
+ if (data) {
140
+ this.start({ token: data.token, payload: data })
141
+
142
+ return data
143
+ }
144
+ },
145
+ sync: async function () {
146
+ const payload = await this.getPayload()
147
+ if (payload) {
148
+ this.token = payload.token
149
+ }
150
+ },
151
+ start: async function ({ token, payload = null }: IStartProps) {
152
+ if (!token) {
153
+ throw new Error("A token and email is needed to start a session")
154
+ }
155
+
156
+ this.token = token
157
+
158
+ if (payload && (await this.setPayload(payload))) {
159
+ Console.success(`Successfully logged in as user ${payload.user_id}`)
160
+ }
161
+ },
162
+ destroy: async function () {
163
+ if (!this.sessionStarted) {
164
+ await this.initialize()
165
+ }
166
+
167
+ await storage.clear()
168
+ this.token = null
169
+ Console.success("You have logged out")
170
+ },
171
+ breakToken: async function () {
172
+ const payload = await this.getPayload()
173
+ if (payload) {
174
+ this.token = "asdasdasdasd"
175
+ await storage.setItem("bc-payload", {
176
+ ...payload,
177
+ token: "asdasdsad",
178
+ })
179
+ Console.success("Token broken successfully")
180
+ }
181
+ },
182
+ }
183
+
184
+ export default Session