@learnpack/learnpack 5.0.215 → 5.0.231

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.
package/src/ui/app.tar.gz CHANGED
Binary file
package/src/utils/api.ts CHANGED
@@ -2,6 +2,10 @@ import Console from "../utils/console"
2
2
  import * as storage from "node-persist"
3
3
  import cli from "cli-ux"
4
4
  import axios from "axios"
5
+ import * as dotenv from "dotenv"
6
+
7
+ dotenv.config()
8
+
5
9
  const HOST = "https://breathecode.herokuapp.com"
6
10
  export const RIGOBOT_HOST = "https://rigobot.herokuapp.com"
7
11
  // export const RIGOBOT_HOST = "https://rigobot-test-cca7d841c9d8.herokuapp.com"
@@ -49,8 +53,7 @@ const fetch = async (
49
53
  if (resp.status === 401)
50
54
  Console.debug("Invalid authentication credentials", `Code: 401`)
51
55
  // throw APIError("Invalid authentication credentials", 401)
52
- else if (resp.status === 404)
53
- throw APIError("Package not found", 404)
56
+ else if (resp.status === 404) throw APIError("Package not found", 404)
54
57
  else if (resp.status >= 500)
55
58
  throw APIError("Impossible to connect with the server", 500)
56
59
  else if (resp.status >= 400) {
@@ -67,8 +70,7 @@ throw APIError("Package not found", 404)
67
70
  } else {
68
71
  throw APIError("Uknown error")
69
72
  }
70
- } else
71
- throw APIError("Uknown error")
73
+ } else throw APIError("Uknown error")
72
74
  } catch (error) {
73
75
  Console.error((error as TypeError).message)
74
76
  throw error
@@ -132,8 +134,7 @@ const publish = async (config: any) => {
132
134
  ]
133
135
 
134
136
  const payload: { [key: string]: string } = {}
135
- for (const k of keys)
136
- config[k] ? (payload[k] = config[k]) : null
137
+ for (const k of keys) config[k] ? (payload[k] = config[k]) : null
137
138
  try {
138
139
  console.log("Package to publish:", payload)
139
140
  cli.action.start("Updating package information...")
@@ -178,8 +179,7 @@ const getPackage = async (slug: string) => {
178
179
  } catch (error) {
179
180
  if ((error as any).status === 404)
180
181
  Console.error(`Package ${slug} does not exist`)
181
- else
182
- Console.error(`Package ${slug} does not exist`)
182
+ else Console.error(`Package ${slug} does not exist`)
183
183
  Console.debug(error)
184
184
  throw error
185
185
  }
@@ -195,8 +195,7 @@ const getLangs = async () => {
195
195
  } catch (error) {
196
196
  if ((error as any).status === 404)
197
197
  Console.error("Package slug does not exist")
198
- else
199
- Console.error("Package slug does not exist")
198
+ else Console.error("Package slug does not exist")
200
199
  Console.debug(error)
201
200
  throw error
202
201
  }
@@ -559,6 +558,76 @@ const createRigoPackage = async (token: string, slug: string, config: any) => {
559
558
  }
560
559
  }
561
560
 
561
+ type TTechnology = {
562
+ slug: string
563
+ lang: string
564
+ }
565
+
566
+ let technologiesCache: TTechnology[] = []
567
+
568
+ export const fetchTechnologies = async () => {
569
+ const BREATHECODE_PERMANENT_TOKEN = process.env.BREATHECODE_PERMANENT_TOKEN
570
+ const LANGS = ["en", "es", "us"]
571
+
572
+ if (!BREATHECODE_PERMANENT_TOKEN) {
573
+ throw new Error(
574
+ "BREATHECODE_PERMANENT_TOKEN is not defined in environment variables"
575
+ )
576
+ }
577
+
578
+ const headers = {
579
+ Authorization: `Token ${BREATHECODE_PERMANENT_TOKEN}`,
580
+ }
581
+
582
+ const results = await Promise.all(
583
+ LANGS.map(lang =>
584
+ axios
585
+ .get(`${HOST}/v1/registry/technology?lang=${lang}`, { headers })
586
+ .then(res => {
587
+ return res.data
588
+ })
589
+ .then(data =>
590
+ data.map((item: any) => ({
591
+ slug: item.slug,
592
+ lang: lang,
593
+ }))
594
+ )
595
+ )
596
+ )
597
+
598
+ const allItems = results.flat()
599
+
600
+ // Remove duplicates by slug+lang combination
601
+ const unique = []
602
+ const seen = new Set()
603
+ for (const item of allItems) {
604
+ const key = `${item.slug}:${item.lang}`
605
+ if (!seen.has(key)) {
606
+ seen.add(key)
607
+ unique.push(item)
608
+ }
609
+ }
610
+
611
+ return unique
612
+ }
613
+
614
+ // Function to update the cache and schedule the next update
615
+ async function updateTechnologiesPeriodically() {
616
+ try {
617
+ technologiesCache = await fetchTechnologies()
618
+ // Uncomment for debugging:
619
+ // console.log('Technologies list updated:', technologiesCache);
620
+ } catch (error: any) {
621
+ console.error("Error updating technologies list:", error)
622
+ } finally {
623
+ setTimeout(updateTechnologiesPeriodically, 24 * 60 * 60 * 1000)
624
+ }
625
+ }
626
+
627
+ updateTechnologiesPeriodically()
628
+
629
+ export const getCurrentTechnologies = () => technologiesCache
630
+
562
631
  export default {
563
632
  login,
564
633
  publish,
@@ -576,4 +645,5 @@ export default {
576
645
  getCategories,
577
646
  updateRigoAssetID,
578
647
  createRigoPackage,
648
+ getCurrentTechnologies,
579
649
  }