@learnpack/learnpack 5.0.67 → 5.0.68

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-tZYXMzIW.js"></script>
13
+ <script type="module" crossorigin src="/creator/assets/index-B01XTAAq.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/creator/assets/index-t6ma_gVm.css">
15
15
  </head>
16
16
  <body>
@@ -1 +1 @@
1
- {"version":"5.0.67","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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false}},"args":[]},"breakToken":{"id":"breakToken","description":"Break the token","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"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":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"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":"Builds the project by copying necessary files and directories into a zip file","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"serve":{"id":"serve","description":"Runs a small server to build tutorials","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"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":"[preview, extension]","options":["extension","preview"]},"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":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]},"translate":{"id":"translate","description":"List all the lessons, the user is able of select many of them to translate to the given languages","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[]}}}
1
+ {"version":"5.0.68","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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false}},"args":[]},"breakToken":{"id":"breakToken","description":"Break the token","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"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":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"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":"Builds the project by copying necessary files and directories into a zip file","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"serve":{"id":"serve","description":"Runs a small server to build tutorials","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"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":"[preview, extension]","options":["extension","preview"]},"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":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]},"translate":{"id":"translate","description":"List all the lessons, the user is able of select many of them to translate to the given languages","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[]}}}
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.67",
4
+ "version": "5.0.68",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "contributors": [
7
7
  {
@@ -0,0 +1,21 @@
1
+ import { useEffect } from "react"
2
+ import { getConsumables, parseConsumables } from "../utils/lib"
3
+ import useStore from "../utils/store"
4
+
5
+ export const ConsumablesManager = () => {
6
+ const auth = useStore((state) => state.auth)
7
+ const setConsumables = useStore((state) => state.setConsumables)
8
+
9
+ useEffect(() => {
10
+ if (auth.bcToken) {
11
+ fetchConsumables()
12
+ }
13
+ }, [auth])
14
+
15
+ const fetchConsumables = async () => {
16
+ const consumables = await getConsumables(auth.bcToken)
17
+ setConsumables(parseConsumables(consumables.voids))
18
+ }
19
+
20
+ return <></>
21
+ }
@@ -3,7 +3,11 @@ import { SVGS } from "../assets/svgs"
3
3
  import { useShallow } from "zustand/react/shallow"
4
4
  import useStore from "../utils/store"
5
5
  import { interactiveCreation } from "../utils/rigo"
6
- import { parseLesson, uploadFileToBucket } from "../utils/lib"
6
+ import {
7
+ parseLesson,
8
+ uploadFileToBucket,
9
+ useConsumableCall,
10
+ } from "../utils/lib"
7
11
  import {
8
12
  createLearnJson,
9
13
  processExercise,
@@ -15,8 +19,30 @@ import Loader from "./Loader"
15
19
  import { Message, TMessage } from "./Message"
16
20
  import { LessonItem, Lesson } from "./LessonItem"
17
21
  import FileUploader from "./FileUploader"
22
+ import { ConsumablesManager } from "./ConsumablesManager"
23
+ import toast from "react-hot-toast"
18
24
 
19
- // types.ts
25
+ const GenerateButton = ({ handleSubmit }: { handleSubmit: () => void }) => {
26
+ const auth = useStore((state) => state.auth)
27
+ return (
28
+ <div className="flex justify-end mt-6">
29
+ <button
30
+ onClick={async () => {
31
+ const success = await useConsumableCall(auth.bcToken, "ai-generation")
32
+ if (success) {
33
+ handleSubmit()
34
+ } else {
35
+ toast.error("You don't have enough credits to generate a course.")
36
+ }
37
+ }}
38
+ className="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 cursor-pointer flex items-center gap-2"
39
+ >
40
+ <span>I'm ready. Create the course for me!</span>
41
+ {SVGS.rigoSoftBlue}
42
+ </button>
43
+ </div>
44
+ )
45
+ }
20
46
 
21
47
  const SyllabusEditor: React.FC = () => {
22
48
  const inputRef = useRef<HTMLTextAreaElement>(null)
@@ -137,6 +163,7 @@ It may take a moment..."
137
163
  />
138
164
  ) : (
139
165
  <div className="flex w-full bg-white rounded-md shadow-md overflow-hidden h-screen ">
166
+ <ConsumablesManager />
140
167
  {/* Sidebar */}
141
168
  <div className="w-1/3 p-6 text-sm text-gray-700 border-r bg-learnpack-blue h-screen overflow-y-auto scrollbar-hide relative">
142
169
  <div className="p-4 rounded-md bg-white shadow-sm">
@@ -264,15 +291,7 @@ It may take a moment..."
264
291
  ))}
265
292
  </div>
266
293
 
267
- <div className="flex justify-end mt-6">
268
- <button
269
- onClick={handleSubmit}
270
- className="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 cursor-pointer flex items-center gap-2"
271
- >
272
- <span>I'm ready. Create the course for me! </span>
273
- {SVGS.rigoSoftBlue}
274
- </button>
275
- </div>
294
+ <GenerateButton handleSubmit={handleSubmit} />
276
295
  </div>
277
296
  </div>
278
297
  )
@@ -1,4 +1,5 @@
1
1
  import axios from "axios"
2
+ import { BREATHECODE_HOST } from "./constants"
2
3
 
3
4
  type ParsedLesson = {
4
5
  id: string
@@ -40,3 +41,82 @@ export const checkParams = () => {
40
41
  const token = urlParams.get("token")
41
42
  return { token }
42
43
  }
44
+
45
+ export async function getConsumables(token: string): Promise<any> {
46
+ const url = `${BREATHECODE_HOST}/v1/payments/me/service/consumable?virtual=true`
47
+
48
+ const headers = {
49
+ Authorization: `Token ${token}`,
50
+ }
51
+
52
+ try {
53
+ const response = await axios.get(url, { headers })
54
+ return response.data
55
+ } catch (error) {
56
+ console.error("Error fetching consumables:", error)
57
+ throw error
58
+ }
59
+ }
60
+
61
+ type ConsumableSlug =
62
+ | "ai-conversation-message"
63
+ | "ai-compilation"
64
+ | "ai-generation"
65
+ | "ai-course-generation"
66
+
67
+ export async function useConsumableCall(
68
+ breathecodeToken: string,
69
+ consumableSlug: ConsumableSlug = "ai-conversation-message"
70
+ ): Promise<boolean> {
71
+ const url = `${BREATHECODE_HOST}/v1/payments/me/service/${consumableSlug}/consumptionsession`
72
+
73
+ const headers = {
74
+ Authorization: `Token ${breathecodeToken}`,
75
+ }
76
+
77
+ try {
78
+ const response = await axios.put(url, {}, { headers })
79
+
80
+ if (response.status >= 200 && response.status < 300) {
81
+ console.log(response.data)
82
+ console.log(`Successfully consumed ${consumableSlug}`)
83
+ return true
84
+ } else {
85
+ console.error(`Request failed with status code: ${response.status}`)
86
+ console.error(`Response: ${response.data}`)
87
+ return false
88
+ }
89
+ } catch (error) {
90
+ console.error(`Error consuming ${consumableSlug}:`, error)
91
+ return false
92
+ }
93
+ }
94
+
95
+ type ConsumableItem = {
96
+ id: number
97
+ how_many: number
98
+ unit_type: string
99
+ valid_until: string | null
100
+ }
101
+
102
+ type VoidEntry = {
103
+ id: number
104
+ slug: string
105
+ balance: { unit: number }
106
+ items: ConsumableItem[]
107
+ }
108
+
109
+ export const parseConsumables = (
110
+ voids: VoidEntry[]
111
+ ): Record<string, number> => {
112
+ const result: Record<string, number> = {}
113
+
114
+ voids.forEach((entry) => {
115
+ const maxHowMany = entry.items.length
116
+ ? Math.max(...entry.items.map((item) => item.how_many))
117
+ : 0
118
+ result[entry.slug] = maxHowMany
119
+ })
120
+
121
+ return result
122
+ }
@@ -27,6 +27,10 @@ type Syllabus = {
27
27
  }[]
28
28
  }
29
29
 
30
+ type Consumables = {
31
+ [key: string]: number
32
+ }
33
+
30
34
  type Store = {
31
35
  auth: Auth
32
36
  formState: FormState
@@ -34,6 +38,8 @@ type Store = {
34
38
  syllabus: Syllabus
35
39
  setSyllabus: (syllabus: Partial<Syllabus>) => void
36
40
  setFormState: (formState: Partial<FormState>) => void
41
+ consumables: Consumables
42
+ setConsumables: (consumables: Partial<Consumables>) => void
37
43
  }
38
44
 
39
45
  const useStore = create<Store>()(
@@ -70,6 +76,19 @@ const useStore = create<Store>()(
70
76
  },
71
77
  uploadedFiles: [],
72
78
  },
79
+ consumables: {},
80
+ setConsumables: (consumables: Partial<Consumables>) =>
81
+ set((state) => {
82
+ const sanitized: Consumables = Object.fromEntries(
83
+ Object.entries(consumables).map(([k, v]) => [k, v ?? 0])
84
+ )
85
+ return {
86
+ consumables: {
87
+ ...state.consumables,
88
+ ...sanitized,
89
+ },
90
+ }
91
+ }),
73
92
  setSyllabus: (syllabus: Partial<Syllabus>) =>
74
93
  set((state) => ({ syllabus: { ...state.syllabus, ...syllabus } })),
75
94
  setAuth: (auth: Auth) => set({ auth }),