@tscircuit/fake-snippets 0.0.106 → 0.0.107
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/CLAUDE.md +92 -0
- package/api/generated-index.js +2 -3
- package/dist/bundle.js +339 -413
- package/dist/index.d.ts +5 -0
- package/dist/index.js +24 -5
- package/dist/schema.d.ts +8 -0
- package/dist/schema.js +3 -1
- package/fake-snippets-api/lib/db/db-client.ts +9 -0
- package/fake-snippets-api/lib/db/schema.ts +3 -0
- package/fake-snippets-api/lib/db/seed.ts +17 -3
- package/fake-snippets-api/routes/api/package_builds/list.ts +0 -1
- package/package.json +3 -2
- package/src/App.tsx +19 -4
- package/src/components/PackageBreadcrumb.tsx +111 -0
- package/src/components/ViewPackagePage/components/sidebar-releases-section.tsx +17 -7
- package/src/components/preview/BuildsList.tsx +74 -168
- package/src/components/preview/ConnectedPackagesList.tsx +22 -5
- package/src/components/preview/ConnectedRepoOverview.tsx +12 -2
- package/src/components/preview/{ConnectedRepoDashboard.tsx → PackageReleasesDashboard.tsx} +30 -74
- package/src/components/preview/index.tsx +7 -4
- package/src/hooks/use-package-builds.ts +0 -48
- package/src/hooks/use-package-release-by-id-or-version.ts +36 -0
- package/src/hooks/use-package-release.ts +32 -0
- package/src/lib/utils/isUuid.ts +5 -0
- package/src/pages/preview-build.tsx +3 -3
- package/src/pages/release-builds.tsx +107 -0
- package/src/pages/release-detail.tsx +118 -0
- package/src/pages/releases.tsx +51 -0
- package/fake-snippets-api/routes/api/package_builds/latest.ts +0 -109
- package/src/pages/view-connected-repo.tsx +0 -49
|
@@ -85,51 +85,3 @@ export const usePackageBuild = (packageBuildId: string | null) => {
|
|
|
85
85
|
},
|
|
86
86
|
)
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
export const useLatestPackageBuild = (
|
|
90
|
-
params: { package_id?: string; package_release_id?: string } | null,
|
|
91
|
-
) => {
|
|
92
|
-
const axios = useAxios()
|
|
93
|
-
|
|
94
|
-
return useQuery<PackageBuild | null, Error & { status: number }>(
|
|
95
|
-
["latestPackageBuild", params],
|
|
96
|
-
async () => {
|
|
97
|
-
if (!params || (!params.package_id && !params.package_release_id)) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
"Either package_id or package_release_id must be provided",
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const { data } = await axios.get<{ package_build: PackageBuild }>(
|
|
104
|
-
"/package_builds/latest",
|
|
105
|
-
{
|
|
106
|
-
params: {
|
|
107
|
-
...(params.package_id ? { package_id: params.package_id } : {}),
|
|
108
|
-
...(params.package_release_id
|
|
109
|
-
? { package_release_id: params.package_release_id }
|
|
110
|
-
: {}),
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
return data.package_build
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
enabled: Boolean(
|
|
119
|
-
params && (params.package_id || params.package_release_id),
|
|
120
|
-
),
|
|
121
|
-
retry: false,
|
|
122
|
-
refetchOnWindowFocus: false,
|
|
123
|
-
},
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const useLatestPackageBuildByPackageId = (packageId: string | null) => {
|
|
128
|
-
return useLatestPackageBuild(packageId ? { package_id: packageId } : null)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export const useLatestPackageBuildByReleaseId = (releaseId?: string | null) => {
|
|
132
|
-
return useLatestPackageBuild(
|
|
133
|
-
releaseId ? { package_release_id: releaseId } : null,
|
|
134
|
-
)
|
|
135
|
-
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
usePackageReleaseById,
|
|
3
|
+
usePackageReleaseByNameAndVersion,
|
|
4
|
+
} from "./use-package-release"
|
|
5
|
+
import { isUuid } from "@/lib/utils/isUuid"
|
|
6
|
+
|
|
7
|
+
export const usePackageReleaseByIdOrVersion = (
|
|
8
|
+
releaseIdOrVersion: string | null,
|
|
9
|
+
packageName?: string | null,
|
|
10
|
+
) => {
|
|
11
|
+
const isReleaseIdUuid = releaseIdOrVersion
|
|
12
|
+
? isUuid(releaseIdOrVersion)
|
|
13
|
+
: false
|
|
14
|
+
|
|
15
|
+
// If it's a UUID, use the ID-based hook
|
|
16
|
+
const releaseByIdQuery = usePackageReleaseById(
|
|
17
|
+
isReleaseIdUuid ? releaseIdOrVersion : null,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
// If it's not a UUID and we have a package name, construct the version-based query
|
|
21
|
+
const packageNameWithVersion =
|
|
22
|
+
!isReleaseIdUuid && packageName && releaseIdOrVersion
|
|
23
|
+
? `${packageName}@${releaseIdOrVersion}`
|
|
24
|
+
: null
|
|
25
|
+
|
|
26
|
+
const releaseByVersionQuery = usePackageReleaseByNameAndVersion(
|
|
27
|
+
packageNameWithVersion,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
// Return the appropriate query result
|
|
31
|
+
if (isReleaseIdUuid) {
|
|
32
|
+
return releaseByIdQuery
|
|
33
|
+
} else {
|
|
34
|
+
return releaseByVersionQuery
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -90,3 +90,35 @@ export const useLatestPackageRelease = (
|
|
|
90
90
|
|
|
91
91
|
return usePackageRelease(query)
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
export const usePackageReleasesByPackageId = (packageId: string | null) => {
|
|
95
|
+
const axios = useAxios()
|
|
96
|
+
|
|
97
|
+
return useQuery<PackageRelease[], Error & { status: number }>(
|
|
98
|
+
["packageReleases", packageId],
|
|
99
|
+
async () => {
|
|
100
|
+
if (!packageId) {
|
|
101
|
+
throw new Error("package_id is required")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const { data } = await axios.post<{ package_releases: PackageRelease[] }>(
|
|
105
|
+
"/package_releases/list",
|
|
106
|
+
{
|
|
107
|
+
package_id: packageId,
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if (!data.package_releases) {
|
|
112
|
+
return []
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return data.package_releases
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
enabled: Boolean(packageId),
|
|
119
|
+
retry: false,
|
|
120
|
+
refetchOnWindowFocus: false,
|
|
121
|
+
staleTime: 0,
|
|
122
|
+
},
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -7,7 +7,7 @@ import { TreeView, TreeDataItem } from "@/components/ui/tree-view"
|
|
|
7
7
|
import { cn } from "@/lib/utils"
|
|
8
8
|
import { PrefetchPageLink } from "@/components/PrefetchPageLink"
|
|
9
9
|
import NotFoundPage from "./404"
|
|
10
|
-
import { getBuildStatus,
|
|
10
|
+
import { getBuildStatus, MOCK_PACKAGE_BUILDS } from "@/components/preview"
|
|
11
11
|
|
|
12
12
|
const MOCK_DEPLOYMENT_FILES: Record<
|
|
13
13
|
string,
|
|
@@ -189,8 +189,8 @@ export default function PreviewBuildPage() {
|
|
|
189
189
|
const buildFsMap = getBuildFsMap(buildId)
|
|
190
190
|
|
|
191
191
|
const build = buildId
|
|
192
|
-
?
|
|
193
|
-
:
|
|
192
|
+
? MOCK_PACKAGE_BUILDS.find((d) => d.package_build_id === buildId)
|
|
193
|
+
: MOCK_PACKAGE_BUILDS[0]
|
|
194
194
|
|
|
195
195
|
if (!build) {
|
|
196
196
|
return <NotFoundPage heading="Build Not Found" />
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useParams } from "wouter"
|
|
2
|
+
import NotFoundPage from "./404"
|
|
3
|
+
import { usePackageByName } from "@/hooks/use-package-by-package-name"
|
|
4
|
+
import { usePackageReleaseByIdOrVersion } from "@/hooks/use-package-release-by-id-or-version"
|
|
5
|
+
import { usePackageBuildsByReleaseId } from "@/hooks/use-package-builds"
|
|
6
|
+
import { BuildsList } from "@/components/preview/BuildsList"
|
|
7
|
+
import Header from "@/components/Header"
|
|
8
|
+
import { useLocation } from "wouter"
|
|
9
|
+
import { PackageBreadcrumb } from "@/components/PackageBreadcrumb"
|
|
10
|
+
import { PackageBuild } from "fake-snippets-api/lib/db/schema"
|
|
11
|
+
|
|
12
|
+
export default function ReleaseBuildsPage() {
|
|
13
|
+
const params = useParams<{
|
|
14
|
+
author: string
|
|
15
|
+
packageName: string
|
|
16
|
+
releaseId: string
|
|
17
|
+
}>()
|
|
18
|
+
|
|
19
|
+
const packageName =
|
|
20
|
+
params?.author && params?.packageName
|
|
21
|
+
? `${params.author}/${params.packageName}`
|
|
22
|
+
: null
|
|
23
|
+
|
|
24
|
+
const [, setLocation] = useLocation()
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
data: pkg,
|
|
28
|
+
isLoading: isLoadingPackage,
|
|
29
|
+
error: packageError,
|
|
30
|
+
} = usePackageByName(packageName)
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
data: packageRelease,
|
|
34
|
+
isLoading: isLoadingRelease,
|
|
35
|
+
error: releaseError,
|
|
36
|
+
} = usePackageReleaseByIdOrVersion(params?.releaseId ?? null, packageName)
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
data: builds,
|
|
40
|
+
isLoading: isLoadingBuilds,
|
|
41
|
+
error: buildsError,
|
|
42
|
+
} = usePackageBuildsByReleaseId(params?.releaseId ?? null)
|
|
43
|
+
|
|
44
|
+
const handleSelectBuild = (build: PackageBuild) => {
|
|
45
|
+
setLocation(`/build/${build.package_build_id}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isLoadingPackage || isLoadingRelease || isLoadingBuilds) {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (packageError?.status === 404 || !pkg) {
|
|
53
|
+
return <NotFoundPage heading="Package Not Found" />
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (releaseError?.status === 404 || !packageRelease) {
|
|
57
|
+
return <NotFoundPage heading="Release Not Found" />
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (buildsError?.status === 404 || !builds?.length) {
|
|
61
|
+
return <NotFoundPage heading="No Builds Found for Release" />
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
<Header />
|
|
67
|
+
<div className="min-h-screen bg-white">
|
|
68
|
+
<div className="bg-gray-50 border-b py-10">
|
|
69
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
70
|
+
<PackageBreadcrumb
|
|
71
|
+
author={params?.author || ""}
|
|
72
|
+
packageName={packageName || ""}
|
|
73
|
+
unscopedName={pkg.unscoped_name}
|
|
74
|
+
currentPage="builds"
|
|
75
|
+
releaseVersion={
|
|
76
|
+
packageRelease.version ||
|
|
77
|
+
`v${packageRelease.package_release_id.slice(-6)}`
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
<div className="flex items-center gap-4">
|
|
81
|
+
<div>
|
|
82
|
+
<h1 className="text-3xl font-bold text-gray-900">
|
|
83
|
+
{pkg.name} - Release Builds
|
|
84
|
+
</h1>
|
|
85
|
+
<p className="text-gray-600 mt-2">
|
|
86
|
+
All builds for release {packageRelease.package_release_id}
|
|
87
|
+
</p>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
|
94
|
+
<div className="space-y-6">
|
|
95
|
+
<div className="flex items-center justify-between">
|
|
96
|
+
<h2 className="text-2xl font-bold text-gray-900">All Builds</h2>
|
|
97
|
+
<p className="text-sm text-gray-600">
|
|
98
|
+
{builds?.length} build{builds?.length !== 1 ? "s" : ""} found
|
|
99
|
+
</p>
|
|
100
|
+
</div>
|
|
101
|
+
{pkg && <BuildsList pkg={pkg} />}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useParams } from "wouter"
|
|
2
|
+
import NotFoundPage from "./404"
|
|
3
|
+
import { usePackageByName } from "@/hooks/use-package-by-package-name"
|
|
4
|
+
import { usePackageReleaseByIdOrVersion } from "@/hooks/use-package-release-by-id-or-version"
|
|
5
|
+
import { usePackageBuild } from "@/hooks/use-package-builds"
|
|
6
|
+
import { ConnectedRepoOverview } from "@/components/preview/ConnectedRepoOverview"
|
|
7
|
+
import Header from "@/components/Header"
|
|
8
|
+
import { Badge } from "@/components/ui/badge"
|
|
9
|
+
import { Button } from "@/components/ui/button"
|
|
10
|
+
import { Calendar, GitBranch, Hash, Copy, Check } from "lucide-react"
|
|
11
|
+
import { useState } from "react"
|
|
12
|
+
import { formatTimeAgo } from "@/lib/utils/formatTimeAgo"
|
|
13
|
+
import { PackageBreadcrumb } from "@/components/PackageBreadcrumb"
|
|
14
|
+
|
|
15
|
+
export default function ReleaseDetailPage() {
|
|
16
|
+
const params = useParams<{
|
|
17
|
+
author: string
|
|
18
|
+
packageName: string
|
|
19
|
+
releaseId?: string
|
|
20
|
+
packageReleaseId?: string
|
|
21
|
+
}>()
|
|
22
|
+
|
|
23
|
+
const packageName =
|
|
24
|
+
params?.author && params?.packageName
|
|
25
|
+
? `${params.author}/${params.packageName}`
|
|
26
|
+
: null
|
|
27
|
+
|
|
28
|
+
const [copied, setCopied] = useState(false)
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
data: pkg,
|
|
32
|
+
isLoading: isLoadingPackage,
|
|
33
|
+
error: packageError,
|
|
34
|
+
} = usePackageByName(packageName)
|
|
35
|
+
|
|
36
|
+
const releaseIdOrVersion =
|
|
37
|
+
params?.releaseId ?? params?.packageReleaseId ?? null
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
data: packageRelease,
|
|
41
|
+
isLoading: isLoadingRelease,
|
|
42
|
+
error: releaseError,
|
|
43
|
+
} = usePackageReleaseByIdOrVersion(releaseIdOrVersion, packageName)
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
data: latestBuild,
|
|
47
|
+
isLoading: isLoadingBuild,
|
|
48
|
+
error: buildError,
|
|
49
|
+
} = usePackageBuild(packageRelease?.latest_package_build_id ?? null)
|
|
50
|
+
|
|
51
|
+
if (isLoadingPackage || isLoadingRelease || isLoadingBuild) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (packageError?.status === 404 || !pkg) {
|
|
56
|
+
return <NotFoundPage heading="Package Not Found" />
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (releaseError?.status === 404 || !packageRelease) {
|
|
60
|
+
return <NotFoundPage heading="Release Not Found" />
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (buildError?.status === 404 || !latestBuild) {
|
|
64
|
+
return <NotFoundPage heading="No Builds Found for Release" />
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
<Header />
|
|
70
|
+
<div className="min-h-screen bg-white">
|
|
71
|
+
{/* Page Header */}
|
|
72
|
+
<div className="bg-gray-50 border-b py-6">
|
|
73
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
74
|
+
{/* Breadcrumb */}
|
|
75
|
+
<PackageBreadcrumb
|
|
76
|
+
author={pkg.owner_github_username || ""}
|
|
77
|
+
packageName={pkg.name}
|
|
78
|
+
unscopedName={pkg.unscoped_name}
|
|
79
|
+
releaseVersion={
|
|
80
|
+
packageRelease.version ||
|
|
81
|
+
`v${packageRelease.package_release_id.slice(-6)}`
|
|
82
|
+
}
|
|
83
|
+
/>
|
|
84
|
+
|
|
85
|
+
{/* Header Content */}
|
|
86
|
+
<div className="flex flex-col lg:flex-row lg:items-start lg:justify-between gap-2">
|
|
87
|
+
<div className="flex-1">
|
|
88
|
+
<div className="flex items-center gap-4 text-sm text-gray-600">
|
|
89
|
+
{packageRelease.is_pr_preview && (
|
|
90
|
+
<div className="flex items-center gap-1">
|
|
91
|
+
<GitBranch className="w-4 h-4" />
|
|
92
|
+
<Badge variant="outline" className="text-xs">
|
|
93
|
+
PR #{packageRelease.github_pr_number}
|
|
94
|
+
</Badge>
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
<div className="flex items-center gap-1">
|
|
98
|
+
<Calendar className="w-4 h-4" />
|
|
99
|
+
<span>
|
|
100
|
+
Created {formatTimeAgo(packageRelease.created_at)}
|
|
101
|
+
</span>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
{/* Main Content */}
|
|
110
|
+
<ConnectedRepoOverview
|
|
111
|
+
build={latestBuild}
|
|
112
|
+
pkg={pkg}
|
|
113
|
+
packageRelease={packageRelease}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useParams } from "wouter"
|
|
2
|
+
import NotFoundPage from "./404"
|
|
3
|
+
import { useLatestPackageRelease } from "@/hooks/use-package-release"
|
|
4
|
+
import { usePackageBuild } from "@/hooks/use-package-builds"
|
|
5
|
+
import { usePackageByName } from "@/hooks/use-package-by-package-name"
|
|
6
|
+
import { PackageReleasesDashboard } from "@/components/preview/PackageReleasesDashboard"
|
|
7
|
+
|
|
8
|
+
export default function ReleasesPage() {
|
|
9
|
+
const params = useParams<{ author: string; packageName: string }>()
|
|
10
|
+
const packageName =
|
|
11
|
+
params?.author && params?.packageName
|
|
12
|
+
? `${params.author}/${params.packageName}`
|
|
13
|
+
: null
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
data: pkg,
|
|
17
|
+
isLoading: isLoadingPackage,
|
|
18
|
+
error: packageError,
|
|
19
|
+
} = usePackageByName(packageName)
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
data: latestRelease,
|
|
23
|
+
isLoading: isLoadingRelease,
|
|
24
|
+
error: releaseError,
|
|
25
|
+
} = useLatestPackageRelease(pkg?.package_id ?? null)
|
|
26
|
+
|
|
27
|
+
// Get the latest build for the latest release to show status and metadata
|
|
28
|
+
const {
|
|
29
|
+
data: latestBuild,
|
|
30
|
+
isLoading: isLoadingBuild,
|
|
31
|
+
error: buildError,
|
|
32
|
+
} = usePackageBuild(latestRelease?.latest_package_build_id ?? null)
|
|
33
|
+
|
|
34
|
+
if (isLoadingPackage || isLoadingRelease || isLoadingBuild) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (packageError?.status === 404 || !pkg) {
|
|
39
|
+
return <NotFoundPage heading="Package Not Found" />
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (releaseError?.status === 404 || !latestRelease) {
|
|
43
|
+
return <NotFoundPage heading="No Releases Found" />
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// If there's no build, we still want to show the releases page
|
|
47
|
+
// The PackageReleasesDashboard will handle the case where latestBuild is null
|
|
48
|
+
return (
|
|
49
|
+
<PackageReleasesDashboard latestBuild={latestBuild ?? null} pkg={pkg} />
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
|
|
2
|
-
import { z } from "zod"
|
|
3
|
-
import { publicMapPackageBuild } from "fake-snippets-api/lib/public-mapping/public-map-package-build"
|
|
4
|
-
|
|
5
|
-
export default withRouteSpec({
|
|
6
|
-
methods: ["GET"],
|
|
7
|
-
auth: "session",
|
|
8
|
-
queryParams: z.object({
|
|
9
|
-
package_id: z.string().optional(),
|
|
10
|
-
package_release_id: z.string().optional(),
|
|
11
|
-
}),
|
|
12
|
-
jsonResponse: z.object({
|
|
13
|
-
package_build: z.any().nullable(),
|
|
14
|
-
}),
|
|
15
|
-
})(async (req, ctx) => {
|
|
16
|
-
const { package_id, package_release_id } = req.query
|
|
17
|
-
|
|
18
|
-
if (!package_id && !package_release_id) {
|
|
19
|
-
return ctx.error(400, {
|
|
20
|
-
error_code: "invalid_request",
|
|
21
|
-
message: "Either package_id or package_release_id must be provided",
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let targetPackageId = package_id
|
|
26
|
-
|
|
27
|
-
if (package_release_id) {
|
|
28
|
-
const packageRelease = ctx.db.packageReleases.find(
|
|
29
|
-
(pr) => pr.package_release_id === package_release_id,
|
|
30
|
-
)
|
|
31
|
-
if (!packageRelease) {
|
|
32
|
-
return ctx.error(404, {
|
|
33
|
-
error_code: "package_release_not_found",
|
|
34
|
-
message: "Package release not found",
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
targetPackageId = packageRelease.package_id
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (targetPackageId) {
|
|
41
|
-
const pkg = ctx.db.packages.find((p) => p.package_id === targetPackageId)
|
|
42
|
-
if (!pkg) {
|
|
43
|
-
return ctx.error(404, {
|
|
44
|
-
error_code: "package_not_found",
|
|
45
|
-
message: "Package not found",
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
if (pkg.creator_account_id !== ctx.auth.account_id) {
|
|
49
|
-
console.log(
|
|
50
|
-
pkg.creator_account_id !== ctx.auth.account_id,
|
|
51
|
-
pkg.creator_account_id,
|
|
52
|
-
ctx.auth.account_id,
|
|
53
|
-
)
|
|
54
|
-
return ctx.error(403, {
|
|
55
|
-
error_code: "unauthorized",
|
|
56
|
-
message: "You are not authorized to access this package",
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let builds = ctx.db.packageBuilds
|
|
62
|
-
|
|
63
|
-
if (package_id) {
|
|
64
|
-
const packageReleases = ctx.db.packageReleases.filter(
|
|
65
|
-
(x) => x.package_id === package_id,
|
|
66
|
-
)
|
|
67
|
-
if (packageReleases.length === 0) {
|
|
68
|
-
return ctx.error(404, {
|
|
69
|
-
error_code: "package_not_found",
|
|
70
|
-
message: "Package not found",
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const packageReleaseIds = packageReleases
|
|
75
|
-
.filter((pr) => pr.package_id === package_id)
|
|
76
|
-
.map((pr) => pr.package_release_id)
|
|
77
|
-
|
|
78
|
-
builds = builds.filter((build) =>
|
|
79
|
-
packageReleaseIds.includes(build.package_release_id),
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (package_release_id) {
|
|
84
|
-
builds = builds.filter(
|
|
85
|
-
(build) => build.package_release_id === package_release_id,
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
builds = builds.sort(
|
|
90
|
-
(a, b) =>
|
|
91
|
-
new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
const latestBuild = builds[0] || null
|
|
95
|
-
|
|
96
|
-
if (!latestBuild) {
|
|
97
|
-
return ctx.json({
|
|
98
|
-
package_build: null,
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const publicBuild = publicMapPackageBuild(latestBuild, {
|
|
103
|
-
include_logs: true,
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
return ctx.json({
|
|
107
|
-
package_build: publicBuild,
|
|
108
|
-
})
|
|
109
|
-
})
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { useParams } from "wouter"
|
|
2
|
-
import NotFoundPage from "./404"
|
|
3
|
-
import { ConnectedRepoDashboard } from "@/components/preview"
|
|
4
|
-
import { usePackageBuild } from "@/hooks/use-package-builds"
|
|
5
|
-
import { usePackageReleaseById } from "@/hooks/use-package-release"
|
|
6
|
-
import { usePackageById } from "@/hooks/use-package-by-package-id"
|
|
7
|
-
|
|
8
|
-
export default function ViewConnectedRepoOverview() {
|
|
9
|
-
const params = useParams<{ buildId: string }>()
|
|
10
|
-
const {
|
|
11
|
-
data: packageBuild,
|
|
12
|
-
isLoading: isLoadingBuild,
|
|
13
|
-
error: buildError,
|
|
14
|
-
} = usePackageBuild(params?.buildId)
|
|
15
|
-
const {
|
|
16
|
-
data: packageRelease,
|
|
17
|
-
isLoading: isLoadingRelease,
|
|
18
|
-
error: releaseError,
|
|
19
|
-
} = usePackageReleaseById(packageBuild?.package_release_id)
|
|
20
|
-
const {
|
|
21
|
-
data: buildPackage,
|
|
22
|
-
isLoading: isLoadingPackage,
|
|
23
|
-
error: packageError,
|
|
24
|
-
} = usePackageById(String(packageRelease?.package_id))
|
|
25
|
-
|
|
26
|
-
if (isLoadingBuild || isLoadingRelease || isLoadingPackage) {
|
|
27
|
-
return null
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (buildError?.status === 404 || !packageBuild) {
|
|
31
|
-
return <NotFoundPage heading="Build Not Found" />
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (releaseError?.status === 404 || !packageRelease) {
|
|
35
|
-
return <NotFoundPage heading="Package Release Not Found" />
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (packageError?.status === 404 || !buildPackage) {
|
|
39
|
-
return <NotFoundPage heading="Package Not Found" />
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<ConnectedRepoDashboard
|
|
44
|
-
latestBuild={packageBuild}
|
|
45
|
-
pkg={buildPackage}
|
|
46
|
-
packageRelease={packageRelease}
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
49
|
-
}
|