@learnpack/learnpack 5.0.346 → 5.0.347
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/lib/commands/publish.d.ts +1 -1
- package/lib/commands/publish.js +9 -2
- package/lib/commands/serve.js +92 -17
- package/lib/utils/api.d.ts +25 -1
- package/lib/utils/api.js +34 -1
- package/package.json +1 -1
- package/src/commands/publish.ts +15 -0
- package/src/commands/serve.ts +105 -34
- package/src/ui/_app/app.js +332 -332
- package/src/ui/app.tar.gz +0 -0
- package/src/utils/api.ts +43 -2
package/src/ui/app.tar.gz
CHANGED
|
Binary file
|
package/src/utils/api.ts
CHANGED
|
@@ -432,6 +432,42 @@ export const validateToken = async (token: string) => {
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
+
/** keep in sync with ide/src/components/Creator/PublishButton.tsx AssetSyncError */
|
|
436
|
+
export type AssetSyncError =
|
|
437
|
+
| { kind: "lang_error"; lang: string; error: { detail: string } }
|
|
438
|
+
| { kind: "package_error"; error: { detail: string } };
|
|
439
|
+
|
|
440
|
+
function parseLearnpackPackageId(raw: unknown): number | null {
|
|
441
|
+
if (raw === undefined || raw === null) return null
|
|
442
|
+
const n = typeof raw === "number" ? raw : Number(raw)
|
|
443
|
+
if (!Number.isFinite(n) || !Number.isInteger(n)) return null
|
|
444
|
+
return n
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* GET Rigobot package by slug after a successful upload. Does not throw.
|
|
449
|
+
* @param rigoToken Rigobot API token (Bearer-style `Token` header value).
|
|
450
|
+
* @param courseSlug Learnpack package slug used in the Rigobot URL path.
|
|
451
|
+
* @returns Resolved numeric package id from Rigobot, or `null` if the request fails, the id is missing, or it is not a finite integer.
|
|
452
|
+
*/
|
|
453
|
+
export async function resolveLearnpackPackageId(
|
|
454
|
+
rigoToken: string,
|
|
455
|
+
courseSlug: string
|
|
456
|
+
): Promise<number | null> {
|
|
457
|
+
if (!rigoToken?.trim() || !courseSlug) return null
|
|
458
|
+
const url = `${RIGOBOT_HOST}/v1/learnpack/package/${encodeURIComponent(
|
|
459
|
+
courseSlug
|
|
460
|
+
)}/`
|
|
461
|
+
try {
|
|
462
|
+
const response = await axios.get<{ id?: unknown }>(url, {
|
|
463
|
+
headers: { Authorization: `Token ${rigoToken.trim()}` },
|
|
464
|
+
})
|
|
465
|
+
return parseLearnpackPackageId(response.data?.id)
|
|
466
|
+
} catch {
|
|
467
|
+
return null
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
435
471
|
type TAssetMissing = {
|
|
436
472
|
slug: string;
|
|
437
473
|
title: string;
|
|
@@ -448,6 +484,7 @@ type TAssetMissing = {
|
|
|
448
484
|
readme_raw: string;
|
|
449
485
|
all_translations: string[];
|
|
450
486
|
academy_id?: number;
|
|
487
|
+
learnpack_id: number;
|
|
451
488
|
};
|
|
452
489
|
|
|
453
490
|
export const createAsset = async (token: string, asset: TAssetMissing) => {
|
|
@@ -475,6 +512,7 @@ export const createAsset = async (token: string, asset: TAssetMissing) => {
|
|
|
475
512
|
intro_video_url: null,
|
|
476
513
|
translations: [asset.lang],
|
|
477
514
|
learnpack_deploy_url: asset.learnpack_deploy_url,
|
|
515
|
+
learnpack_id: asset.learnpack_id,
|
|
478
516
|
technologies: asset.technologies,
|
|
479
517
|
readme_raw: asset.readme_raw,
|
|
480
518
|
all_translations: asset.all_translations,
|
|
@@ -536,17 +574,19 @@ export const doesAssetExists = async (
|
|
|
536
574
|
const updateAsset = async (
|
|
537
575
|
token: string,
|
|
538
576
|
assetSlug: string,
|
|
539
|
-
asset: Partial<TAssetMissing>
|
|
577
|
+
asset: Partial<TAssetMissing> & { learnpack_id: number }
|
|
540
578
|
) => {
|
|
541
579
|
const url = `https://breathecode.herokuapp.com/v1/registry/asset/me/${assetSlug}`
|
|
542
580
|
const headers = {
|
|
543
581
|
Authorization: `Token ${token}`,
|
|
544
582
|
}
|
|
545
583
|
|
|
584
|
+
const body = { ...asset, learnpack_id: asset.learnpack_id }
|
|
585
|
+
|
|
546
586
|
console.log("[BC] PUT", url, "| academy_id:", asset.academy_id ?? "none")
|
|
547
587
|
|
|
548
588
|
try {
|
|
549
|
-
const response = await axios.put(url,
|
|
589
|
+
const response = await axios.put(url, body, { headers })
|
|
550
590
|
return response.data
|
|
551
591
|
} catch (error: any) {
|
|
552
592
|
console.error("Failed to update asset:", error)
|
|
@@ -708,6 +748,7 @@ export default {
|
|
|
708
748
|
createAsset,
|
|
709
749
|
doesAssetExists,
|
|
710
750
|
updateAsset,
|
|
751
|
+
resolveLearnpackPackageId,
|
|
711
752
|
getCategories,
|
|
712
753
|
updateRigoPackage,
|
|
713
754
|
createRigoPackage,
|