@tscircuit/fake-snippets 0.0.101 → 0.0.102

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 (56) hide show
  1. package/api/generated-index.js +23 -1
  2. package/bun.lock +2 -2
  3. package/dist/bundle.js +530 -367
  4. package/dist/index.d.ts +29 -2
  5. package/dist/index.js +18 -1
  6. package/dist/schema.d.ts +94 -1
  7. package/dist/schema.js +17 -1
  8. package/fake-snippets-api/lib/db/db-client.ts +6 -1
  9. package/fake-snippets-api/lib/db/schema.ts +15 -0
  10. package/fake-snippets-api/lib/public-mapping/public-map-package.ts +2 -0
  11. package/fake-snippets-api/routes/api/github/installations/create_new_installation_redirect.ts +75 -0
  12. package/fake-snippets-api/routes/api/github/repos/list_available.ts +91 -0
  13. package/fake-snippets-api/routes/api/packages/update.ts +4 -0
  14. package/package.json +2 -2
  15. package/src/App.tsx +10 -1
  16. package/src/components/CreateReleaseDialog.tsx +124 -0
  17. package/src/components/FileSidebar.tsx +128 -23
  18. package/src/components/PackageBuildsPage/package-build-header.tsx +9 -1
  19. package/src/components/PageSearchComponent.tsx +2 -2
  20. package/src/components/SearchComponent.tsx +2 -2
  21. package/src/components/SuspenseRunFrame.tsx +2 -2
  22. package/src/components/TrendingPackagesCarousel.tsx +2 -2
  23. package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +1 -0
  24. package/src/components/ViewPackagePage/components/sidebar-about-section.tsx +1 -0
  25. package/src/components/dialogs/GitHubRepositorySelector.tsx +123 -0
  26. package/src/components/dialogs/create-use-dialog.tsx +8 -2
  27. package/src/components/dialogs/edit-package-details-dialog.tsx +22 -3
  28. package/src/components/dialogs/view-ts-files-dialog.tsx +178 -33
  29. package/src/components/package-port/CodeAndPreview.tsx +4 -1
  30. package/src/components/package-port/CodeEditor.tsx +42 -35
  31. package/src/components/package-port/CodeEditorHeader.tsx +6 -4
  32. package/src/components/package-port/EditorNav.tsx +94 -37
  33. package/src/components/preview/BuildsList.tsx +238 -0
  34. package/src/components/preview/ConnectedRepoDashboard.tsx +258 -0
  35. package/src/components/preview/ConnectedRepoOverview.tsx +454 -0
  36. package/src/components/preview/ConnectedRepoSettings.tsx +343 -0
  37. package/src/components/preview/ConnectedReposCards.tsx +191 -0
  38. package/src/components/preview/index.tsx +207 -0
  39. package/src/components/ui/tree-view.tsx +23 -6
  40. package/src/hooks/use-axios.ts +2 -2
  41. package/src/hooks/use-create-release-dialog.ts +160 -0
  42. package/src/hooks/use-package-details-form.ts +7 -0
  43. package/src/hooks/use-packages-base-api-url.ts +1 -1
  44. package/src/hooks/use-sign-in.ts +2 -2
  45. package/src/hooks/useFileManagement.ts +22 -2
  46. package/src/index.css +4 -0
  47. package/src/lib/utils/formatTimeAgo.ts +10 -0
  48. package/src/lib/utils/isValidFileName.ts +15 -3
  49. package/src/pages/dashboard.tsx +2 -2
  50. package/src/pages/dev-login.tsx +2 -2
  51. package/src/pages/latest.tsx +2 -2
  52. package/src/pages/preview-build.tsx +380 -0
  53. package/src/pages/search.tsx +2 -2
  54. package/src/pages/trending.tsx +2 -2
  55. package/src/pages/user-profile.tsx +32 -24
  56. package/src/pages/view-connected-repo.tsx +24 -0
package/dist/index.d.ts CHANGED
@@ -622,6 +622,7 @@ declare const packageSchema: z.ZodObject<{
622
622
  creator_account_id: z.ZodString;
623
623
  owner_org_id: z.ZodString;
624
624
  owner_github_username: z.ZodNullable<z.ZodString>;
625
+ github_repo_full_name: z.ZodNullable<z.ZodString>;
625
626
  name: z.ZodString;
626
627
  unscoped_name: z.ZodString;
627
628
  description: z.ZodNullable<z.ZodString>;
@@ -663,6 +664,7 @@ declare const packageSchema: z.ZodObject<{
663
664
  creator_account_id: string;
664
665
  owner_org_id: string;
665
666
  owner_github_username: string | null;
667
+ github_repo_full_name: string | null;
666
668
  is_snippet: boolean;
667
669
  is_board: boolean;
668
670
  is_package: boolean;
@@ -689,6 +691,7 @@ declare const packageSchema: z.ZodObject<{
689
691
  creator_account_id: string;
690
692
  owner_org_id: string;
691
693
  owner_github_username: string | null;
694
+ github_repo_full_name: string | null;
692
695
  latest_package_release_id: string | null;
693
696
  latest_version: string | null;
694
697
  ai_usage_instructions: string | null;
@@ -929,6 +932,7 @@ declare const createDatabase: ({ seed }?: {
929
932
  creator_account_id: string;
930
933
  owner_org_id: string;
931
934
  owner_github_username: string | null;
935
+ github_repo_full_name: string | null;
932
936
  is_snippet: boolean;
933
937
  is_board: boolean;
934
938
  is_package: boolean;
@@ -1073,6 +1077,17 @@ declare const createDatabase: ({ seed }?: {
1073
1077
  datasheet_pdf_urls: string[] | null;
1074
1078
  ai_description: string | null;
1075
1079
  }[];
1080
+ githubInstallations: {
1081
+ created_at: string;
1082
+ updated_at: string;
1083
+ account_id: string;
1084
+ github_username: string;
1085
+ github_installation_id: string;
1086
+ installation_id: string;
1087
+ is_active: boolean;
1088
+ access_token?: string | null | undefined;
1089
+ access_token_expires_at?: string | null | undefined;
1090
+ }[];
1076
1091
  }, "addOrder" | "getOrderById" | "getOrderFilesByOrderId" | "addOrderQuote" | "getOrderQuoteById" | "getJlcpcbOrderStatesByOrderId" | "getJlcpcbOrderStepRunsByJlcpcbOrderStateId" | "updateOrder" | "addJlcpcbOrderState" | "updateJlcpcbOrderState" | "addOrderFile" | "getOrderFileById" | "addAccount" | "addAccountPackage" | "getAccountPackageById" | "updateAccountPackage" | "deleteAccountPackage" | "addSnippet" | "getLatestSnippets" | "getTrendingSnippets" | "getPackagesByAuthor" | "getSnippetByAuthorAndName" | "updateSnippet" | "getSnippetById" | "searchSnippets" | "searchPackages" | "searchAccounts" | "deleteSnippet" | "addSession" | "getSessions" | "createLoginPage" | "getLoginPage" | "updateLoginPage" | "getAccount" | "updateAccount" | "createSession" | "addStar" | "removeStar" | "hasStarred" | "addPackage" | "updatePackage" | "getPackageById" | "getPackageReleaseById" | "addPackageRelease" | "updatePackageRelease" | "deletePackageFile" | "addPackageFile" | "updatePackageFile" | "getStarCount" | "getPackageFilesByReleaseId" | "updatePackageReleaseFsSha" | "addAiReview" | "updateAiReview" | "getAiReviewById" | "listAiReviews" | "addDatasheet" | "getDatasheetById" | "getDatasheetByChipName" | "listDatasheets" | "updateDatasheet"> & {
1077
1092
  addOrder: (order: Omit<Order, "order_id">) => Order;
1078
1093
  getOrderById: (orderId: string) => Order | undefined;
@@ -1137,7 +1152,7 @@ declare const createDatabase: ({ seed }?: {
1137
1152
  addStar: (accountId: string, packageId: string) => AccountPackage;
1138
1153
  removeStar: (accountId: string, packageId: string) => void;
1139
1154
  hasStarred: (accountId: string, packageId: string) => boolean;
1140
- addPackage: (_package: Omit<z.input<typeof packageSchema>, "package_id">) => Package;
1155
+ addPackage: (_package: Omit<z.input<typeof packageSchema>, "package_id" | "github_repo_full_name">) => Package;
1141
1156
  updatePackage: (packageId: string, updates: Partial<Package>) => Package | undefined;
1142
1157
  getPackageById: (packageId: string) => Package | undefined;
1143
1158
  getPackageReleaseById: (packageReleaseId: string) => PackageRelease | undefined;
@@ -1283,6 +1298,7 @@ declare const createDatabase: ({ seed }?: {
1283
1298
  creator_account_id: string;
1284
1299
  owner_org_id: string;
1285
1300
  owner_github_username: string | null;
1301
+ github_repo_full_name: string | null;
1286
1302
  is_snippet: boolean;
1287
1303
  is_board: boolean;
1288
1304
  is_package: boolean;
@@ -1427,6 +1443,17 @@ declare const createDatabase: ({ seed }?: {
1427
1443
  datasheet_pdf_urls: string[] | null;
1428
1444
  ai_description: string | null;
1429
1445
  }[];
1446
+ githubInstallations: {
1447
+ created_at: string;
1448
+ updated_at: string;
1449
+ account_id: string;
1450
+ github_username: string;
1451
+ github_installation_id: string;
1452
+ installation_id: string;
1453
+ is_active: boolean;
1454
+ access_token?: string | null | undefined;
1455
+ access_token_expires_at?: string | null | undefined;
1456
+ }[];
1430
1457
  }, "addOrder" | "getOrderById" | "getOrderFilesByOrderId" | "addOrderQuote" | "getOrderQuoteById" | "getJlcpcbOrderStatesByOrderId" | "getJlcpcbOrderStepRunsByJlcpcbOrderStateId" | "updateOrder" | "addJlcpcbOrderState" | "updateJlcpcbOrderState" | "addOrderFile" | "getOrderFileById" | "addAccount" | "addAccountPackage" | "getAccountPackageById" | "updateAccountPackage" | "deleteAccountPackage" | "addSnippet" | "getLatestSnippets" | "getTrendingSnippets" | "getPackagesByAuthor" | "getSnippetByAuthorAndName" | "updateSnippet" | "getSnippetById" | "searchSnippets" | "searchPackages" | "searchAccounts" | "deleteSnippet" | "addSession" | "getSessions" | "createLoginPage" | "getLoginPage" | "updateLoginPage" | "getAccount" | "updateAccount" | "createSession" | "addStar" | "removeStar" | "hasStarred" | "addPackage" | "updatePackage" | "getPackageById" | "getPackageReleaseById" | "addPackageRelease" | "updatePackageRelease" | "deletePackageFile" | "addPackageFile" | "updatePackageFile" | "getStarCount" | "getPackageFilesByReleaseId" | "updatePackageReleaseFsSha" | "addAiReview" | "updateAiReview" | "getAiReviewById" | "listAiReviews" | "addDatasheet" | "getDatasheetById" | "getDatasheetByChipName" | "listDatasheets" | "updateDatasheet"> & {
1431
1458
  addOrder: (order: Omit<Order, "order_id">) => Order;
1432
1459
  getOrderById: (orderId: string) => Order | undefined;
@@ -1491,7 +1518,7 @@ declare const createDatabase: ({ seed }?: {
1491
1518
  addStar: (accountId: string, packageId: string) => AccountPackage;
1492
1519
  removeStar: (accountId: string, packageId: string) => void;
1493
1520
  hasStarred: (accountId: string, packageId: string) => boolean;
1494
- addPackage: (_package: Omit<z.input<typeof packageSchema>, "package_id">) => Package;
1521
+ addPackage: (_package: Omit<z.input<typeof packageSchema>, "package_id" | "github_repo_full_name">) => Package;
1495
1522
  updatePackage: (packageId: string, updates: Partial<Package>) => Package | undefined;
1496
1523
  getPackageById: (packageId: string) => Package | undefined;
1497
1524
  getPackageReleaseById: (packageReleaseId: string) => PackageRelease | undefined;
package/dist/index.js CHANGED
@@ -144,6 +144,19 @@ var datasheetSchema = z.object({
144
144
  datasheet_pdf_urls: z.array(z.string()).nullable(),
145
145
  ai_description: z.string().nullable()
146
146
  });
147
+ var githubInstallationSchema = z.object({
148
+ github_installation_id: z.string(),
149
+ account_id: z.string(),
150
+ installation_id: z.string(),
151
+ // GitHub App installation ID
152
+ github_username: z.string(),
153
+ created_at: z.string().datetime(),
154
+ updated_at: z.string().datetime(),
155
+ is_active: z.boolean().default(true),
156
+ access_token: z.string().nullable().optional(),
157
+ // For storing GitHub access token
158
+ access_token_expires_at: z.string().datetime().nullable().optional()
159
+ });
147
160
  var accountSnippetSchema = z.object({
148
161
  account_id: z.string(),
149
162
  snippet_id: z.string(),
@@ -213,6 +226,7 @@ var packageSchema = z.object({
213
226
  creator_account_id: z.string(),
214
227
  owner_org_id: z.string(),
215
228
  owner_github_username: z.string().nullable(),
229
+ github_repo_full_name: z.string().nullable(),
216
230
  name: z.string(),
217
231
  unscoped_name: z.string(),
218
232
  description: z.string().nullable(),
@@ -290,7 +304,8 @@ var databaseSchema = z.object({
290
304
  jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([]),
291
305
  orderQuotes: z.array(orderQuoteSchema).default([]),
292
306
  aiReviews: z.array(aiReviewSchema).default([]),
293
- datasheets: z.array(datasheetSchema).default([])
307
+ datasheets: z.array(datasheetSchema).default([]),
308
+ githubInstallations: z.array(githubInstallationSchema).default([])
294
309
  });
295
310
 
296
311
  // fake-snippets-api/lib/db/autoload-dev-packages.ts
@@ -2264,6 +2279,7 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
2264
2279
  star_count: 0,
2265
2280
  created_at: currentTime,
2266
2281
  updated_at: currentTime,
2282
+ github_repo_full_name: null,
2267
2283
  ai_description: "placeholder ai description",
2268
2284
  ai_usage_instructions: "placeholder ai usage instructions",
2269
2285
  is_snippet: true,
@@ -2981,6 +2997,7 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
2981
2997
  const timestamp = Date.now();
2982
2998
  const newPackage = {
2983
2999
  package_id: `package_${timestamp}`,
3000
+ github_repo_full_name: null,
2984
3001
  ..._package
2985
3002
  };
2986
3003
  set((state) => ({
package/dist/schema.d.ts CHANGED
@@ -582,6 +582,38 @@ declare const datasheetSchema: z.ZodObject<{
582
582
  ai_description: string | null;
583
583
  }>;
584
584
  type Datasheet = z.infer<typeof datasheetSchema>;
585
+ declare const githubInstallationSchema: z.ZodObject<{
586
+ github_installation_id: z.ZodString;
587
+ account_id: z.ZodString;
588
+ installation_id: z.ZodString;
589
+ github_username: z.ZodString;
590
+ created_at: z.ZodString;
591
+ updated_at: z.ZodString;
592
+ is_active: z.ZodDefault<z.ZodBoolean>;
593
+ access_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
594
+ access_token_expires_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
595
+ }, "strip", z.ZodTypeAny, {
596
+ created_at: string;
597
+ updated_at: string;
598
+ account_id: string;
599
+ github_username: string;
600
+ github_installation_id: string;
601
+ installation_id: string;
602
+ is_active: boolean;
603
+ access_token?: string | null | undefined;
604
+ access_token_expires_at?: string | null | undefined;
605
+ }, {
606
+ created_at: string;
607
+ updated_at: string;
608
+ account_id: string;
609
+ github_username: string;
610
+ github_installation_id: string;
611
+ installation_id: string;
612
+ is_active?: boolean | undefined;
613
+ access_token?: string | null | undefined;
614
+ access_token_expires_at?: string | null | undefined;
615
+ }>;
616
+ type GithubInstallation = z.infer<typeof githubInstallationSchema>;
585
617
  declare const accountSnippetSchema: z.ZodObject<{
586
618
  account_id: z.ZodString;
587
619
  snippet_id: z.ZodString;
@@ -763,6 +795,7 @@ declare const packageSchema: z.ZodObject<{
763
795
  creator_account_id: z.ZodString;
764
796
  owner_org_id: z.ZodString;
765
797
  owner_github_username: z.ZodNullable<z.ZodString>;
798
+ github_repo_full_name: z.ZodNullable<z.ZodString>;
766
799
  name: z.ZodString;
767
800
  unscoped_name: z.ZodString;
768
801
  description: z.ZodNullable<z.ZodString>;
@@ -804,6 +837,7 @@ declare const packageSchema: z.ZodObject<{
804
837
  creator_account_id: string;
805
838
  owner_org_id: string;
806
839
  owner_github_username: string | null;
840
+ github_repo_full_name: string | null;
807
841
  is_snippet: boolean;
808
842
  is_board: boolean;
809
843
  is_package: boolean;
@@ -830,6 +864,7 @@ declare const packageSchema: z.ZodObject<{
830
864
  creator_account_id: string;
831
865
  owner_org_id: string;
832
866
  owner_github_username: string | null;
867
+ github_repo_full_name: string | null;
833
868
  latest_package_release_id: string | null;
834
869
  latest_version: string | null;
835
870
  ai_usage_instructions: string | null;
@@ -1264,6 +1299,7 @@ declare const databaseSchema: z.ZodObject<{
1264
1299
  creator_account_id: z.ZodString;
1265
1300
  owner_org_id: z.ZodString;
1266
1301
  owner_github_username: z.ZodNullable<z.ZodString>;
1302
+ github_repo_full_name: z.ZodNullable<z.ZodString>;
1267
1303
  name: z.ZodString;
1268
1304
  unscoped_name: z.ZodString;
1269
1305
  description: z.ZodNullable<z.ZodString>;
@@ -1305,6 +1341,7 @@ declare const databaseSchema: z.ZodObject<{
1305
1341
  creator_account_id: string;
1306
1342
  owner_org_id: string;
1307
1343
  owner_github_username: string | null;
1344
+ github_repo_full_name: string | null;
1308
1345
  is_snippet: boolean;
1309
1346
  is_board: boolean;
1310
1347
  is_package: boolean;
@@ -1331,6 +1368,7 @@ declare const databaseSchema: z.ZodObject<{
1331
1368
  creator_account_id: string;
1332
1369
  owner_org_id: string;
1333
1370
  owner_github_username: string | null;
1371
+ github_repo_full_name: string | null;
1334
1372
  latest_package_release_id: string | null;
1335
1373
  latest_version: string | null;
1336
1374
  ai_usage_instructions: string | null;
@@ -1763,6 +1801,37 @@ declare const databaseSchema: z.ZodObject<{
1763
1801
  datasheet_pdf_urls: string[] | null;
1764
1802
  ai_description: string | null;
1765
1803
  }>, "many">>;
1804
+ githubInstallations: z.ZodDefault<z.ZodArray<z.ZodObject<{
1805
+ github_installation_id: z.ZodString;
1806
+ account_id: z.ZodString;
1807
+ installation_id: z.ZodString;
1808
+ github_username: z.ZodString;
1809
+ created_at: z.ZodString;
1810
+ updated_at: z.ZodString;
1811
+ is_active: z.ZodDefault<z.ZodBoolean>;
1812
+ access_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1813
+ access_token_expires_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1814
+ }, "strip", z.ZodTypeAny, {
1815
+ created_at: string;
1816
+ updated_at: string;
1817
+ account_id: string;
1818
+ github_username: string;
1819
+ github_installation_id: string;
1820
+ installation_id: string;
1821
+ is_active: boolean;
1822
+ access_token?: string | null | undefined;
1823
+ access_token_expires_at?: string | null | undefined;
1824
+ }, {
1825
+ created_at: string;
1826
+ updated_at: string;
1827
+ account_id: string;
1828
+ github_username: string;
1829
+ github_installation_id: string;
1830
+ installation_id: string;
1831
+ is_active?: boolean | undefined;
1832
+ access_token?: string | null | undefined;
1833
+ access_token_expires_at?: string | null | undefined;
1834
+ }>, "many">>;
1766
1835
  }, "strip", z.ZodTypeAny, {
1767
1836
  idCounter: number;
1768
1837
  snippets: {
@@ -1880,6 +1949,7 @@ declare const databaseSchema: z.ZodObject<{
1880
1949
  creator_account_id: string;
1881
1950
  owner_org_id: string;
1882
1951
  owner_github_username: string | null;
1952
+ github_repo_full_name: string | null;
1883
1953
  is_snippet: boolean;
1884
1954
  is_board: boolean;
1885
1955
  is_package: boolean;
@@ -2024,6 +2094,17 @@ declare const databaseSchema: z.ZodObject<{
2024
2094
  datasheet_pdf_urls: string[] | null;
2025
2095
  ai_description: string | null;
2026
2096
  }[];
2097
+ githubInstallations: {
2098
+ created_at: string;
2099
+ updated_at: string;
2100
+ account_id: string;
2101
+ github_username: string;
2102
+ github_installation_id: string;
2103
+ installation_id: string;
2104
+ is_active: boolean;
2105
+ access_token?: string | null | undefined;
2106
+ access_token_expires_at?: string | null | undefined;
2107
+ }[];
2027
2108
  }, {
2028
2109
  idCounter?: number | undefined;
2029
2110
  snippets?: {
@@ -2137,6 +2218,7 @@ declare const databaseSchema: z.ZodObject<{
2137
2218
  creator_account_id: string;
2138
2219
  owner_org_id: string;
2139
2220
  owner_github_username: string | null;
2221
+ github_repo_full_name: string | null;
2140
2222
  latest_package_release_id: string | null;
2141
2223
  latest_version: string | null;
2142
2224
  ai_usage_instructions: string | null;
@@ -2285,7 +2367,18 @@ declare const databaseSchema: z.ZodObject<{
2285
2367
  datasheet_pdf_urls: string[] | null;
2286
2368
  ai_description: string | null;
2287
2369
  }[] | undefined;
2370
+ githubInstallations?: {
2371
+ created_at: string;
2372
+ updated_at: string;
2373
+ account_id: string;
2374
+ github_username: string;
2375
+ github_installation_id: string;
2376
+ installation_id: string;
2377
+ is_active?: boolean | undefined;
2378
+ access_token?: string | null | undefined;
2379
+ access_token_expires_at?: string | null | undefined;
2380
+ }[] | undefined;
2288
2381
  }>;
2289
2382
  type DatabaseSchema = z.infer<typeof databaseSchema>;
2290
2383
 
2291
- export { type Account, type AccountPackage, type AccountSnippet, type AiReview, type DatabaseSchema, type Datasheet, type JlcpcbOrderState, type JlcpcbOrderStepRun, type LoginPage, type Order, type OrderFile, type OrderQuote, type Package, type PackageFile, type PackageRelease, type QuotedComponent, type Session, type ShippingOption, type Snippet, accountPackageSchema, accountSchema, accountSnippetSchema, aiReviewSchema, databaseSchema, datasheetPinInformationSchema, datasheetSchema, errorResponseSchema, errorSchema, jlcpcbOrderStateSchema, jlcpcbOrderStepRunSchema, loginPageSchema, orderFileSchema, orderQuoteSchema, orderSchema, packageFileSchema, packageReleaseSchema, packageSchema, quotedComponentSchema, sessionSchema, shippingInfoSchema, snippetSchema };
2384
+ export { type Account, type AccountPackage, type AccountSnippet, type AiReview, type DatabaseSchema, type Datasheet, type GithubInstallation, type JlcpcbOrderState, type JlcpcbOrderStepRun, type LoginPage, type Order, type OrderFile, type OrderQuote, type Package, type PackageFile, type PackageRelease, type QuotedComponent, type Session, type ShippingOption, type Snippet, accountPackageSchema, accountSchema, accountSnippetSchema, aiReviewSchema, databaseSchema, datasheetPinInformationSchema, datasheetSchema, errorResponseSchema, errorSchema, githubInstallationSchema, jlcpcbOrderStateSchema, jlcpcbOrderStepRunSchema, loginPageSchema, orderFileSchema, orderQuoteSchema, orderSchema, packageFileSchema, packageReleaseSchema, packageSchema, quotedComponentSchema, sessionSchema, shippingInfoSchema, snippetSchema };
package/dist/schema.js CHANGED
@@ -139,6 +139,19 @@ var datasheetSchema = z.object({
139
139
  datasheet_pdf_urls: z.array(z.string()).nullable(),
140
140
  ai_description: z.string().nullable()
141
141
  });
142
+ var githubInstallationSchema = z.object({
143
+ github_installation_id: z.string(),
144
+ account_id: z.string(),
145
+ installation_id: z.string(),
146
+ // GitHub App installation ID
147
+ github_username: z.string(),
148
+ created_at: z.string().datetime(),
149
+ updated_at: z.string().datetime(),
150
+ is_active: z.boolean().default(true),
151
+ access_token: z.string().nullable().optional(),
152
+ // For storing GitHub access token
153
+ access_token_expires_at: z.string().datetime().nullable().optional()
154
+ });
142
155
  var accountSnippetSchema = z.object({
143
156
  account_id: z.string(),
144
157
  snippet_id: z.string(),
@@ -208,6 +221,7 @@ var packageSchema = z.object({
208
221
  creator_account_id: z.string(),
209
222
  owner_org_id: z.string(),
210
223
  owner_github_username: z.string().nullable(),
224
+ github_repo_full_name: z.string().nullable(),
211
225
  name: z.string(),
212
226
  unscoped_name: z.string(),
213
227
  description: z.string().nullable(),
@@ -285,7 +299,8 @@ var databaseSchema = z.object({
285
299
  jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([]),
286
300
  orderQuotes: z.array(orderQuoteSchema).default([]),
287
301
  aiReviews: z.array(aiReviewSchema).default([]),
288
- datasheets: z.array(datasheetSchema).default([])
302
+ datasheets: z.array(datasheetSchema).default([]),
303
+ githubInstallations: z.array(githubInstallationSchema).default([])
289
304
  });
290
305
  export {
291
306
  accountPackageSchema,
@@ -297,6 +312,7 @@ export {
297
312
  datasheetSchema,
298
313
  errorResponseSchema,
299
314
  errorSchema,
315
+ githubInstallationSchema,
300
316
  jlcpcbOrderStateSchema,
301
317
  jlcpcbOrderStepRunSchema,
302
318
  loginPageSchema,
@@ -265,6 +265,7 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
265
265
  star_count: 0,
266
266
  created_at: currentTime,
267
267
  updated_at: currentTime,
268
+ github_repo_full_name: null,
268
269
  ai_description: "placeholder ai description",
269
270
  ai_usage_instructions: "placeholder ai usage instructions",
270
271
  is_snippet: true,
@@ -1225,11 +1226,15 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
1225
1226
  )
1226
1227
  },
1227
1228
  addPackage: (
1228
- _package: Omit<z.input<typeof packageSchema>, "package_id">,
1229
+ _package: Omit<
1230
+ z.input<typeof packageSchema>,
1231
+ "package_id" | "github_repo_full_name"
1232
+ >,
1229
1233
  ): Package => {
1230
1234
  const timestamp = Date.now()
1231
1235
  const newPackage = {
1232
1236
  package_id: `package_${timestamp}`,
1237
+ github_repo_full_name: null,
1233
1238
  ..._package,
1234
1239
  }
1235
1240
  set((state) => ({
@@ -167,6 +167,19 @@ export const datasheetSchema = z.object({
167
167
  })
168
168
  export type Datasheet = z.infer<typeof datasheetSchema>
169
169
 
170
+ export const githubInstallationSchema = z.object({
171
+ github_installation_id: z.string(),
172
+ account_id: z.string(),
173
+ installation_id: z.string(), // GitHub App installation ID
174
+ github_username: z.string(),
175
+ created_at: z.string().datetime(),
176
+ updated_at: z.string().datetime(),
177
+ is_active: z.boolean().default(true),
178
+ access_token: z.string().nullable().optional(), // For storing GitHub access token
179
+ access_token_expires_at: z.string().datetime().nullable().optional(),
180
+ })
181
+ export type GithubInstallation = z.infer<typeof githubInstallationSchema>
182
+
170
183
  // TODO: Remove this schema after migration to accountPackages is complete
171
184
  export const accountSnippetSchema = z.object({
172
185
  account_id: z.string(),
@@ -258,6 +271,7 @@ export const packageSchema = z.object({
258
271
  creator_account_id: z.string(),
259
272
  owner_org_id: z.string(),
260
273
  owner_github_username: z.string().nullable(),
274
+ github_repo_full_name: z.string().nullable(),
261
275
  name: z.string(),
262
276
  unscoped_name: z.string(),
263
277
  description: z.string().nullable(),
@@ -345,5 +359,6 @@ export const databaseSchema = z.object({
345
359
  orderQuotes: z.array(orderQuoteSchema).default([]),
346
360
  aiReviews: z.array(aiReviewSchema).default([]),
347
361
  datasheets: z.array(datasheetSchema).default([]),
362
+ githubInstallations: z.array(githubInstallationSchema).default([]),
348
363
  })
349
364
  export type DatabaseSchema = z.infer<typeof databaseSchema>
@@ -26,6 +26,7 @@ export const publicMapPackage = (internalPackage: {
26
26
  is_private: boolean | null
27
27
  is_unlisted: boolean | null
28
28
  latest_package_release_fs_sha: string | null
29
+ github_repo_full_name?: string | null
29
30
  }): zt.Package => {
30
31
  return {
31
32
  ...internalPackage,
@@ -37,6 +38,7 @@ export const publicMapPackage = (internalPackage: {
37
38
  star_count: internalPackage.star_count ?? 0,
38
39
  created_at: internalPackage.created_at,
39
40
  updated_at: internalPackage.updated_at,
41
+ github_repo_full_name: internalPackage.github_repo_full_name ?? null,
40
42
  is_private: internalPackage.is_private ?? false,
41
43
  is_public: internalPackage.is_private === true ? false : true,
42
44
  is_unlisted:
@@ -0,0 +1,75 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+
4
+ export default withRouteSpec({
5
+ methods: ["GET"],
6
+ auth: "session",
7
+ })(async (req, ctx) => {
8
+ const account = ctx.db.getAccount(ctx.auth.account_id)
9
+
10
+ if (!account) {
11
+ return new Response("Account not found", { status: 401 })
12
+ }
13
+
14
+ // Get return_to_page from query params
15
+ const url = new URL(req.url)
16
+ const returnToPage = url.searchParams.get("return_to_page") || "/"
17
+
18
+ // Check if user already has an active GitHub installation
19
+ const existingInstallation = ctx.db.githubInstallations.find(
20
+ (installation) =>
21
+ installation.account_id === ctx.auth.account_id && installation.is_active,
22
+ )
23
+
24
+ if (existingInstallation) {
25
+ // If installation already exists, redirect back
26
+ return new Response("", {
27
+ status: 302,
28
+ headers: {
29
+ Location: returnToPage,
30
+ },
31
+ })
32
+ }
33
+
34
+ // Create a new GitHub installation (simulating the user completing the GitHub App installation)
35
+ const githubInstallationId = `fake_gh_installation_${Date.now()}`
36
+ const mockInstallationId = `${Date.now()}` // Mock GitHub App installation ID
37
+
38
+ const newInstallation = {
39
+ github_installation_id: githubInstallationId,
40
+ account_id: ctx.auth.account_id,
41
+ installation_id: mockInstallationId,
42
+ github_username: account.github_username,
43
+ created_at: new Date().toISOString(),
44
+ updated_at: new Date().toISOString(),
45
+ is_active: true,
46
+ access_token: `ghs_mock_token_${Date.now()}`, // Mock access token
47
+ access_token_expires_at: new Date(Date.now() + 3600000).toISOString(), // 1 hour from now
48
+ }
49
+
50
+ ctx.db.githubInstallations.push(newInstallation)
51
+
52
+ // Return HTML page that shows installation success and redirects back
53
+ return new Response(
54
+ `
55
+ <html>
56
+ <head>
57
+ <title>GitHub Installation Complete</title>
58
+ <meta http-equiv="refresh" content="3;url=${returnToPage}">
59
+ </head>
60
+ <body style="font-family: Arial, sans-serif; padding: 40px; text-align: center;">
61
+ <h1>✅ GitHub Installation Complete!</h1>
62
+ <p>Your GitHub account has been successfully connected to tscircuit.</p>
63
+ <p>You can now access your repositories in the package settings.</p>
64
+ <p>Redirecting you back in 3 seconds...</p>
65
+ <a href="${returnToPage}" style="color: #0066cc; text-decoration: none; font-weight: bold;">Click here if you're not redirected automatically</a>
66
+ </body>
67
+ </html>
68
+ `,
69
+ {
70
+ headers: {
71
+ "Content-Type": "text/html; charset=utf-8",
72
+ },
73
+ },
74
+ )
75
+ })
@@ -0,0 +1,91 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+
4
+ export default withRouteSpec({
5
+ methods: ["GET"],
6
+ auth: "session",
7
+ jsonResponse: z.object({
8
+ repos: z.array(
9
+ z.object({
10
+ unscoped_name: z.string(),
11
+ full_name: z.string(),
12
+ private: z.boolean(),
13
+ owner: z.object({
14
+ login: z.string(),
15
+ }),
16
+ description: z.string().nullable(),
17
+ default_branch: z.string(),
18
+ }),
19
+ ),
20
+ }),
21
+ })(async (_req, ctx) => {
22
+ const account = ctx.db.getAccount(ctx.auth.account_id)
23
+
24
+ if (!account) {
25
+ return ctx.error(401, {
26
+ error_code: "account_not_found",
27
+ message: "Account not found",
28
+ })
29
+ }
30
+
31
+ // Check if user has GitHub account connected
32
+ if (!account.github_username) {
33
+ return ctx.error(400, {
34
+ error_code: "github_not_connected",
35
+ message:
36
+ "GitHub account not connected. Please connect your GitHub account first.",
37
+ })
38
+ }
39
+
40
+ // Check if user has a GitHub installation
41
+ const githubInstallation = ctx.db.githubInstallations.find(
42
+ (installation) =>
43
+ installation.account_id === ctx.auth.account_id && installation.is_active,
44
+ )
45
+
46
+ if (!githubInstallation) {
47
+ // Return empty array if no GitHub installation found
48
+ return ctx.json({
49
+ repos: [],
50
+ })
51
+ }
52
+
53
+ // Mock repositories for demonstration
54
+ // In a real implementation, this would fetch from GitHub API using the installation access token
55
+ const mockRepos = [
56
+ {
57
+ unscoped_name: "my-electronics-project",
58
+ full_name: `${account.github_username}/my-electronics-project`,
59
+ owner: {
60
+ login: account.github_username,
61
+ },
62
+ description: "Arduino-based sensor monitoring system",
63
+ private: false,
64
+ default_branch: "main",
65
+ },
66
+ {
67
+ unscoped_name: "pcb-designs",
68
+ full_name: `${account.github_username}/pcb-designs`,
69
+ owner: {
70
+ login: account.github_username,
71
+ },
72
+ description: "Collection of PCB designs for various projects",
73
+ private: true,
74
+ default_branch: "main",
75
+ },
76
+ {
77
+ unscoped_name: "tscircuit-examples",
78
+ full_name: `${account.github_username}/tscircuit-examples`,
79
+ owner: {
80
+ login: account.github_username,
81
+ },
82
+ description: "Examples and tutorials for tscircuit",
83
+ private: false,
84
+ default_branch: "main",
85
+ },
86
+ ]
87
+
88
+ return ctx.json({
89
+ repos: mockRepos,
90
+ })
91
+ })
@@ -18,6 +18,7 @@ export default withRouteSpec({
18
18
  .optional(),
19
19
  description: z.string().optional(),
20
20
  website: z.string().optional(),
21
+ github_repo_full_name: z.string().optional(),
21
22
  is_private: z.boolean().optional(),
22
23
  is_unlisted: z.boolean().optional(),
23
24
  default_view: z.enum(["files", "3d", "pcb", "schematic"]).optional(),
@@ -38,6 +39,7 @@ export default withRouteSpec({
38
39
  website,
39
40
  is_private,
40
41
  is_unlisted,
42
+ github_repo_full_name,
41
43
  default_view,
42
44
  } = req.jsonBody
43
45
 
@@ -81,6 +83,8 @@ export default withRouteSpec({
81
83
  description: description ?? existingPackage.description,
82
84
  unscoped_name: name ?? existingPackage.unscoped_name,
83
85
  website: website ?? existingPackage.website,
86
+ github_repo_full_name:
87
+ github_repo_full_name ?? existingPackage.github_repo_full_name,
84
88
  is_private: is_private ?? existingPackage.is_private,
85
89
  is_public:
86
90
  is_private !== undefined ? !is_private : existingPackage.is_public,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/fake-snippets",
3
- "version": "0.0.101",
3
+ "version": "0.0.102",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -83,7 +83,7 @@
83
83
  "@tscircuit/mm": "^0.0.8",
84
84
  "@tscircuit/pcb-viewer": "^1.11.194",
85
85
  "@tscircuit/prompt-benchmarks": "^0.0.28",
86
- "@tscircuit/runframe": "0.0.736",
86
+ "@tscircuit/runframe": "0.0.764",
87
87
  "@tscircuit/schematic-viewer": "^2.0.21",
88
88
  "@types/babel__standalone": "^7.1.7",
89
89
  "@types/bun": "^1.1.10",