@tscircuit/fake-snippets 0.0.107 → 0.0.108

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.
Files changed (35) hide show
  1. package/api/generated-index.js +82 -22
  2. package/biome.json +7 -1
  3. package/bun-tests/fake-snippets-api/routes/package_builds/get.test.ts +0 -15
  4. package/bun-tests/fake-snippets-api/routes/package_builds/list.test.ts +0 -12
  5. package/dist/bundle.js +23 -23
  6. package/dist/index.d.ts +21 -15
  7. package/dist/index.js +17 -17
  8. package/dist/schema.d.ts +24 -24
  9. package/dist/schema.js +5 -5
  10. package/fake-snippets-api/lib/db/db-client.ts +10 -1
  11. package/fake-snippets-api/lib/db/schema.ts +3 -3
  12. package/fake-snippets-api/lib/db/seed.ts +6 -9
  13. package/fake-snippets-api/lib/public-mapping/public-map-package-build.ts +0 -3
  14. package/fake-snippets-api/lib/public-mapping/public-map-package-release.ts +3 -0
  15. package/package.json +1 -1
  16. package/src/App.tsx +12 -9
  17. package/src/components/FileSidebar.tsx +14 -159
  18. package/src/components/PackageBreadcrumb.tsx +1 -1
  19. package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +1 -1
  20. package/src/components/ViewPackagePage/components/sidebar-about-section.tsx +18 -2
  21. package/src/components/ViewPackagePage/components/sidebar-releases-section.tsx +1 -1
  22. package/src/components/preview/BuildsList.tsx +20 -9
  23. package/src/components/preview/ConnectedPackagesList.tsx +73 -60
  24. package/src/components/preview/ConnectedRepoOverview.tsx +160 -154
  25. package/src/components/preview/PackageReleasesDashboard.tsx +11 -5
  26. package/src/components/preview/index.tsx +16 -153
  27. package/src/index.css +24 -0
  28. package/src/lib/utils/transformFilesToTreeData.tsx +195 -0
  29. package/src/pages/404.tsx +3 -5
  30. package/src/pages/preview-release.tsx +269 -0
  31. package/src/pages/release-builds.tsx +0 -8
  32. package/src/pages/release-detail.tsx +17 -15
  33. package/src/pages/releases.tsx +5 -1
  34. package/src/hooks/use-snippets-base-api-url.ts +0 -3
  35. package/src/pages/preview-build.tsx +0 -380
@@ -89,7 +89,10 @@ function getHtmlWithModifiedSeoTags({
89
89
  `
90
90
 
91
91
  // First replace SEO tags
92
- let modifiedHtml = `${htmlContent.substring(0, seoStartIndex)}${seoTags}${htmlContent.substring(seoEndIndex)}`
92
+ let modifiedHtml = `${htmlContent.substring(
93
+ 0,
94
+ seoStartIndex,
95
+ )}${seoTags}${htmlContent.substring(seoEndIndex)}`
93
96
 
94
97
  // Then handle SSR data injection
95
98
  if (ssrPackageData) {
@@ -176,21 +179,25 @@ async function handleDatasheetPage(req, res) {
176
179
 
177
180
  async function handleCustomPackageHtml(req, res) {
178
181
  // Get the author and package name
179
- const [_, author, unscopedPackageName] = req.url.split("?")[0].split("/")
182
+ const [_, author, unscopedPackageName, other] = req.url
183
+ .split("?")[0]
184
+ .split("/")
185
+ if (other == "releases" || other == "release") {
186
+ throw new Error("Release route")
187
+ }
180
188
  if (!author || !unscopedPackageName) {
181
189
  throw new Error("Invalid author/package URL")
182
190
  }
183
191
  if (author === "datasheets") {
184
192
  throw new Error("Datasheet route")
185
193
  }
186
- if (author === "build" || unscopedPackageName === "view-connected-repo") {
187
- throw new Error("Build route - not a package")
188
- }
189
194
 
190
195
  const packageNotFoundHtml = getHtmlWithModifiedSeoTags({
191
196
  title: "Package Not Found - tscircuit",
192
197
  description: `The package ${author}/${unscopedPackageName} could not be found.`,
193
- canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(unscopedPackageName)}`,
198
+ canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(
199
+ unscopedPackageName,
200
+ )}`,
194
201
  })
195
202
  const packageDetails = await ky
196
203
  .get(`${REGISTRY_URL}/packages/get`, {
@@ -249,19 +256,29 @@ async function handleCustomPackageHtml(req, res) {
249
256
  }
250
257
 
251
258
  const description = he.encode(
252
- `${packageInfo.description || packageInfo.ai_description || "A tscircuit component created by " + author} ${packageInfo.ai_usage_instructions ?? ""}`,
259
+ `${
260
+ packageInfo.description ||
261
+ packageInfo.ai_description ||
262
+ "A tscircuit component created by " + author
263
+ } ${packageInfo.ai_usage_instructions ?? ""}`,
253
264
  )
254
265
  const title = he.encode(`${packageInfo.name} - tscircuit`)
255
266
 
256
267
  const allowedViews = ["schematic", "pcb", "assembly", "3d"]
257
268
  const defaultView = packageInfo.default_view || "pcb"
258
269
  const thumbnailView = allowedViews.includes(defaultView) ? defaultView : "pcb"
259
- const imageUrl = `${REGISTRY_URL}/packages/images/${he.encode(author)}/${he.encode(unscopedPackageName)}/${thumbnailView}.png?fs_sha=${packageInfo.latest_package_release_fs_sha}`
270
+ const imageUrl = `${REGISTRY_URL}/packages/images/${he.encode(
271
+ author,
272
+ )}/${he.encode(unscopedPackageName)}/${thumbnailView}.png?fs_sha=${
273
+ packageInfo.latest_package_release_fs_sha
274
+ }`
260
275
 
261
276
  const html = getHtmlWithModifiedSeoTags({
262
277
  title,
263
278
  description,
264
- canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(unscopedPackageName)}`,
279
+ canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(
280
+ unscopedPackageName,
281
+ )}`,
265
282
  imageUrl,
266
283
  ssrPackageData: { package: packageInfo, packageRelease, packageFiles },
267
284
  })
@@ -272,7 +289,6 @@ async function handleCustomPackageHtml(req, res) {
272
289
  res.setHeader("Vary", "Accept-Encoding")
273
290
  res.status(200).send(html)
274
291
  }
275
-
276
292
  async function handleCustomPage(req, res) {
277
293
  const [_, page] = req.url.split("?")[0].split("/")
278
294
 
@@ -298,6 +314,57 @@ async function handleCustomPage(req, res) {
298
314
  res.status(200).send(html)
299
315
  }
300
316
 
317
+ async function handleReleasePreview(req, res) {
318
+ const [_, author, unscopedPackageName, releaseId] = req.url
319
+ .split("?")[0]
320
+ .split("/")
321
+
322
+ if (!author || !unscopedPackageName || !releaseId) {
323
+ throw new Error("Invalid author/package/release URL")
324
+ }
325
+ const packageDetails = await ky
326
+ .get(`${REGISTRY_URL}/packages/get`, {
327
+ searchParams: {
328
+ name: `${author}/${unscopedPackageName}`,
329
+ },
330
+ })
331
+ .json()
332
+ .catch((e) => {
333
+ if (String(e).includes("404")) {
334
+ return null
335
+ }
336
+ throw e
337
+ })
338
+ const packageNotFoundHtml = getHtmlWithModifiedSeoTags({
339
+ title: "Package Not Found - tscircuit",
340
+ description: `Release for package ${author}/${unscopedPackageName} could not be found.`,
341
+ canonicalUrl: `${BASE_URL}/${he.encode(author)}/${he.encode(
342
+ unscopedPackageName,
343
+ )}`,
344
+ })
345
+ if (!packageDetails) {
346
+ res.setHeader("Content-Type", "text/html; charset=utf-8")
347
+ res.setHeader("Cache-Control", cacheControlHeader)
348
+ res.setHeader("Vary", "Accept-Encoding")
349
+ res.status(404).send(packageNotFoundHtml)
350
+ return
351
+ }
352
+
353
+ const { package: packageInfo } = packageDetails
354
+ const title = he.encode(`Release preview for ${packageInfo.name} - tscircuit`)
355
+
356
+ const html = getHtmlWithModifiedSeoTags({
357
+ title,
358
+ description: pageDescriptions["releases"],
359
+ ssrPackageData: { package: packageInfo },
360
+ })
361
+
362
+ res.setHeader("Content-Type", "text/html; charset=utf-8")
363
+ res.setHeader("Cache-Control", cacheControlHeader)
364
+ res.setHeader("Vary", "Accept-Encoding")
365
+ res.status(200).send(html)
366
+ }
367
+
301
368
  export default async function handler(req, res) {
302
369
  const urlPath = req.url.split("?")[0]
303
370
  if (urlPath === "/api/generated-index") {
@@ -310,22 +377,15 @@ export default async function handler(req, res) {
310
377
 
311
378
  const pathParts = req.url.split("?")[0].split("/")
312
379
 
313
- if (pathParts[1] === "build" && pathParts[2]) {
314
- const pageDescription = getPageDescription("view-connected-repo")
315
- const html = getHtmlWithModifiedSeoTags({
316
- title: `Preview Build For ${pathParts[2]} - tscircuit`,
317
- description: pageDescription,
318
- canonicalUrl: `${BASE_URL}/build/${pathParts[2]}`,
319
- })
320
- res.setHeader("Content-Type", "text/html; charset=utf-8")
321
- res.setHeader("Cache-Control", cacheControlHeader)
322
- res.setHeader("Vary", "Accept-Encoding")
323
- res.status(200).send(html)
380
+ try {
381
+ await handleCustomPackageHtml(req, res)
324
382
  return
383
+ } catch (e) {
384
+ console.warn(e)
325
385
  }
326
386
 
327
387
  try {
328
- await handleCustomPackageHtml(req, res)
388
+ await handleReleasePreview(req, res)
329
389
  return
330
390
  } catch (e) {
331
391
  console.warn(e)
package/biome.json CHANGED
@@ -8,7 +8,13 @@
8
8
  "indentStyle": "space"
9
9
  },
10
10
  "files": {
11
- "ignore": ["cosmos-export", "dist", "package.json", ".vercel"]
11
+ "ignore": [
12
+ "cosmos-export",
13
+ "dist",
14
+ "package.json",
15
+ ".vercel",
16
+ "src/index.css"
17
+ ]
12
18
  },
13
19
  "javascript": {
14
20
  "formatter": {
@@ -71,9 +71,6 @@ test("GET /api/package_builds/get - returns 403 for unauthorized package build a
71
71
  build_error_last_updated_at: new Date().toISOString(),
72
72
  build_logs: null,
73
73
  preview_url: "https://preview.tscircuit.com/pb_test",
74
- branch_name: "main",
75
- commit_message: "Test build",
76
- commit_author: "jane.doe",
77
74
  })
78
75
 
79
76
  const res = await axios.get(
@@ -126,9 +123,6 @@ test("GET /api/package_builds/get - successfully returns package build with logs
126
123
  ).toISOString(),
127
124
  build_logs: buildLogs.join(" "),
128
125
  preview_url: "https://preview.tscircuit.com/pb_1a2b3c4d",
129
- branch_name: "main",
130
- commit_message: "Add new LED component with improved brightness control",
131
- commit_author: "john.doe",
132
126
  })
133
127
 
134
128
  const res = await axios.get(
@@ -174,9 +168,6 @@ test("GET /api/package_builds/get - returns package build without logs when incl
174
168
  build_error_last_updated_at: new Date().toISOString(),
175
169
  build_logs: "Some build logs",
176
170
  preview_url: "https://preview.tscircuit.com/pb_test",
177
- branch_name: "main",
178
- commit_message: "Test build",
179
- commit_author: "john.doe",
180
171
  })
181
172
 
182
173
  const res = await axios.get(
@@ -222,9 +213,6 @@ test("GET /api/package_builds/get - handles build with errors", async () => {
222
213
  build_error_last_updated_at: new Date().toISOString(),
223
214
  build_logs: null,
224
215
  preview_url: null,
225
- branch_name: "feature/new-component",
226
- commit_message: "Add broken component",
227
- commit_author: "john.doe",
228
216
  })
229
217
 
230
218
  const res = await axios.get(
@@ -274,9 +262,6 @@ test("GET /api/package_builds/get - handles build in progress", async () => {
274
262
  build_error_last_updated_at: new Date().toISOString(),
275
263
  build_logs: null,
276
264
  preview_url: null,
277
- branch_name: "main",
278
- commit_message: "Building in progress",
279
- commit_author: "john.doe",
280
265
  })
281
266
 
282
267
  const res = await axios.get(
@@ -125,9 +125,6 @@ test("GET /api/package_builds/list - returns created builds", async () => {
125
125
  ).toISOString(),
126
126
  build_logs: null,
127
127
  preview_url: "https://preview.tscircuit.com/pb_1a2b3c4d",
128
- branch_name: "main",
129
- commit_message: "Add new LED component with improved brightness control",
130
- commit_author: "john.doe",
131
128
  })
132
129
 
133
130
  const res = await axios.get(
@@ -175,9 +172,6 @@ test("GET /api/package_builds/list - sorts builds by created_at descending", asy
175
172
  ).toISOString(),
176
173
  build_logs: null,
177
174
  preview_url: "https://preview.tscircuit.com/pb_1",
178
- branch_name: "main",
179
- commit_message: "First build",
180
- commit_author: "john.doe",
181
175
  })
182
176
 
183
177
  db.addPackageBuild({
@@ -210,9 +204,6 @@ test("GET /api/package_builds/list - sorts builds by created_at descending", asy
210
204
  ).toISOString(),
211
205
  build_logs: null,
212
206
  preview_url: "https://preview.tscircuit.com/pb_2",
213
- branch_name: "main",
214
- commit_message: "Second build",
215
- commit_author: "john.doe",
216
207
  })
217
208
 
218
209
  const res = await axios.get(
@@ -286,9 +277,6 @@ test("GET /api/package_builds/list - returns created builds with logs or not", a
286
277
  ).toISOString(),
287
278
  build_logs: buildLogs.join(" "),
288
279
  preview_url: "https://preview.tscircuit.com/pb_1a2b3c4d",
289
- branch_name: "main",
290
- commit_message: "Add new LED component with improved brightness control",
291
- commit_author: "john.doe",
292
280
  })
293
281
 
294
282
  const resWithoutLogs = await axios.get(