@learnpack/learnpack 5.0.240 → 5.0.246

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-DJn8b8wj.js"></script>
13
+ <script type="module" crossorigin src="/creator/assets/index-CZYzWk3G.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/creator/assets/index-DmpsXknz.css">
15
15
  </head>
16
16
  <body>
@@ -23,6 +23,7 @@ export type FormState = {
23
23
  currentStep: string;
24
24
  title: string;
25
25
  purpose: string;
26
+ slug: string;
26
27
  };
27
28
  export type Syllabus = {
28
29
  lessons: Lesson[];
@@ -23,6 +23,7 @@ type TAssetMissing = {
23
23
  author: number;
24
24
  preview: string;
25
25
  readme_raw: string;
26
+ all_translations: string[];
26
27
  };
27
28
  export declare const createAsset: (token: string, asset: TAssetMissing) => Promise<any>;
28
29
  export declare const doesAssetExists: (token: string, assetSlug: string) => Promise<{
package/lib/utils/api.js CHANGED
@@ -420,7 +420,7 @@ const getCategories = async (token) => {
420
420
  const updateRigoAssetID = async (token, slug, asset_id) => {
421
421
  const url = `${exports.RIGOBOT_HOST}/v1/learnpack/package/${slug}/`;
422
422
  const headers = {
423
- Authorization: `Token ${token}`,
423
+ Authorization: `Token ${token.trim()}`,
424
424
  };
425
425
  try {
426
426
  const response = await axios_1.default.put(url, { asset_id }, { headers });
@@ -1,5 +1,5 @@
1
1
  import { Server as SocketIOServer } from "socket.io";
2
2
  export declare function initSocketIO(server: any): SocketIOServer<import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, any>;
3
3
  export declare function emitToCourse(courseSlug: string, event: string, payload: any): void;
4
- export declare function emitToNotification(notificationId: string, payload: any): void;
4
+ export declare function emitToNotification(notificationId: string, payload: any, retry?: number): void;
5
5
  export declare function getSocketIO(): SocketIOServer<import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, any>;
@@ -62,11 +62,18 @@ function emitToCourse(courseSlug, event, payload) {
62
62
  socket.emit(event, payload);
63
63
  }
64
64
  }
65
- function emitToNotification(notificationId, payload) {
66
- console.log("Emitting to notification", notificationId, payload);
65
+ function emitToNotification(notificationId, payload, retry = 0) {
67
66
  const socketIds = notificationSocketMap.get(notificationId);
68
- if (!socketIds || socketIds.size === 0)
67
+ if (!socketIds || socketIds.size === 0) {
68
+ if (retry > 3) {
69
+ console.log("❌ Notification", notificationId, "not found");
70
+ return;
71
+ }
72
+ setTimeout(() => {
73
+ emitToNotification(notificationId, payload, retry + 1);
74
+ }, 3000);
69
75
  return;
76
+ }
70
77
  for (const id of socketIds) {
71
78
  const socket = socketStore.get(id);
72
79
  if (socket)
@@ -60,6 +60,11 @@ type TCreateStructuredPreviewReadmeInputs = {
60
60
  tutorial_info: string;
61
61
  };
62
62
  export declare const createStructuredPreviewReadme: (token: string, inputs: TCreateStructuredPreviewReadmeInputs, webhookUrl?: string) => Promise<any>;
63
+ export declare const translateCourseMetadata: (token: string, inputs: {
64
+ title: string;
65
+ description: string;
66
+ destination_lang_code: string;
67
+ }) => Promise<any>;
63
68
  export declare function createPreviewReadme(tutorialDir: string, packageInfo: PackageInfo, rigoToken: string, readmeContents: string[]): Promise<void>;
64
69
  type TReduceReadmeInputs = {
65
70
  lesson: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPackageAuthor = exports.fillSidebarJSON = exports.generateCourseShortName = exports.isValidRigoToken = exports.createStructuredPreviewReadme = exports.readmeCreator = exports.createCodingReadme = exports.createCodeFile = exports.interactiveCreation = exports.generateCourseIntroduction = exports.translateExercise = exports.generateImage = exports.hasCreatorPermission = exports.createReadme = void 0;
3
+ exports.isPackageAuthor = exports.fillSidebarJSON = exports.generateCourseShortName = exports.isValidRigoToken = exports.translateCourseMetadata = exports.createStructuredPreviewReadme = exports.readmeCreator = exports.createCodingReadme = exports.createCodeFile = exports.interactiveCreation = exports.generateCourseIntroduction = exports.translateExercise = exports.generateImage = exports.hasCreatorPermission = exports.createReadme = void 0;
4
4
  exports.downloadImage = downloadImage;
5
5
  exports.createPreviewReadme = createPreviewReadme;
6
6
  exports.makeReadmeReadable = makeReadmeReadable;
@@ -191,6 +191,16 @@ const createStructuredPreviewReadme = async (token, inputs, webhookUrl) => {
191
191
  return response.data;
192
192
  };
193
193
  exports.createStructuredPreviewReadme = createStructuredPreviewReadme;
194
+ const translateCourseMetadata = async (token, inputs) => {
195
+ const response = await axios_1.default.post(`${api_1.RIGOBOT_HOST}/v1/prompting/completion/translate-course-metadata/`, { inputs, include_purpose_objective: false, execute_async: false }, {
196
+ headers: {
197
+ "Content-Type": "application/json",
198
+ Authorization: "Token " + token,
199
+ },
200
+ });
201
+ return response.data;
202
+ };
203
+ exports.translateCourseMetadata = translateCourseMetadata;
194
204
  async function createPreviewReadme(tutorialDir, packageInfo, rigoToken, readmeContents) {
195
205
  const readmeFilename = `README.md`;
196
206
  const readmeContent = await (0, exports.generateCourseIntroduction)(rigoToken, {
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.240",
4
+ "version": "5.0.246",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "contributors": [
7
7
  {
@@ -19,6 +19,7 @@ import api, { getConsumable, RIGOBOT_HOST, TAcademy } from "../utils/api"
19
19
  import * as prompts from "prompts"
20
20
  import { isValidRigoToken } from "../utils/rigoActions"
21
21
  import { minutesToISO8601Duration } from "../utils/misc"
22
+ import { slugify } from "../utils/creatorUtilities"
22
23
 
23
24
  const uploadZipEndpont = RIGOBOT_HOST + "/v1/learnpack/upload"
24
25
 
@@ -27,7 +28,8 @@ export const handleAssetCreation = async (
27
28
  learnJson: any,
28
29
  selectedLang: string,
29
30
  learnpackDeployUrl: string,
30
- b64IndexReadme: string
31
+ b64IndexReadme: string,
32
+ all_translations: string[] = []
31
33
  ) => {
32
34
  const categories: Record<string, number> = {
33
35
  us: 9,
@@ -43,15 +45,13 @@ export const handleAssetCreation = async (
43
45
  try {
44
46
  const user = await api.validateToken(sessionPayload.token)
45
47
 
46
- const { exists } = await api.doesAssetExists(
47
- sessionPayload.token,
48
- learnJson.slug
49
- )
48
+ const slug = slugify(learnJson.title[selectedLang]).slice(0, 50)
49
+ const { exists } = await api.doesAssetExists(sessionPayload.token, slug)
50
50
 
51
51
  if (!exists) {
52
52
  Console.info("Asset does not exist in this academy, creating it")
53
53
  const asset = await api.createAsset(sessionPayload.token, {
54
- slug: learnJson.slug,
54
+ slug: slug,
55
55
  title: learnJson.title[selectedLang],
56
56
  lang: selectedLang,
57
57
  description: learnJson.description[selectedLang],
@@ -63,6 +63,7 @@ export const handleAssetCreation = async (
63
63
  author: user.id,
64
64
  preview: learnJson.preview,
65
65
  readme_raw: b64IndexReadme,
66
+ all_translations,
66
67
  })
67
68
  await api.updateRigoAssetID(
68
69
  sessionPayload.token,
@@ -70,26 +71,26 @@ export const handleAssetCreation = async (
70
71
  asset.id
71
72
  )
72
73
  Console.info("Asset created with id", asset.id)
73
- } else {
74
- Console.info("Asset exists, updating it")
75
- const asset = await api.updateAsset(
76
- sessionPayload.token,
77
- learnJson.slug,
78
- {
79
- learnpack_deploy_url: learnpackDeployUrl,
80
- title: learnJson.title[selectedLang],
81
- description: learnJson.description[selectedLang],
82
- }
83
- )
84
- await api.updateRigoAssetID(
85
- sessionPayload.rigobotToken,
86
- learnJson.slug,
87
- asset.id
88
- )
89
- Console.info("Asset updated with id", asset.id)
74
+ return asset
90
75
  }
76
+
77
+ Console.info("Asset exists, updating it")
78
+ const asset = await api.updateAsset(sessionPayload.token, slug, {
79
+ learnpack_deploy_url: learnpackDeployUrl,
80
+ title: learnJson.title[selectedLang],
81
+ description: learnJson.description[selectedLang],
82
+ all_translations,
83
+ })
84
+ await api.updateRigoAssetID(
85
+ sessionPayload.rigobotToken.trim(),
86
+ learnJson.slug,
87
+ asset.id
88
+ )
89
+ Console.info("Asset updated with id", asset.id)
90
+ return asset
91
91
  } catch (error) {
92
92
  Console.error("Error updating or creating asset:", error)
93
+ return null
93
94
  }
94
95
  }
95
96
 
@@ -442,7 +443,8 @@ class BuildCommand extends SessionCommand {
442
443
  learnJson,
443
444
  "us",
444
445
  res.data.url,
445
- ""
446
+ "",
447
+ []
446
448
  )
447
449
  } catch (error) {
448
450
  if (axios.isAxiosError(error)) {