@tscircuit/fake-snippets 0.0.100 → 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.
- package/api/generated-index.js +23 -1
- package/bun.lock +2 -2
- package/dist/bundle.js +620 -412
- package/dist/index.d.ts +33 -4
- package/dist/index.js +43 -1
- package/dist/schema.d.ts +94 -1
- package/dist/schema.js +17 -1
- package/fake-snippets-api/lib/db/db-client.ts +38 -1
- package/fake-snippets-api/lib/db/schema.ts +15 -0
- package/fake-snippets-api/lib/public-mapping/public-map-package.ts +2 -0
- package/fake-snippets-api/routes/api/accounts/search.ts +20 -0
- package/fake-snippets-api/routes/api/github/installations/create_new_installation_redirect.ts +75 -0
- package/fake-snippets-api/routes/api/github/repos/list_available.ts +91 -0
- package/fake-snippets-api/routes/api/packages/update.ts +4 -0
- package/package.json +2 -2
- package/src/App.tsx +10 -1
- package/src/components/CmdKMenu.tsx +154 -19
- package/src/components/CreateReleaseDialog.tsx +124 -0
- package/src/components/FileSidebar.tsx +128 -23
- package/src/components/Header2.tsx +106 -25
- package/src/components/PackageBuildsPage/package-build-header.tsx +28 -16
- package/src/components/PageSearchComponent.tsx +2 -2
- package/src/components/SearchComponent.tsx +2 -2
- package/src/components/SuspenseRunFrame.tsx +2 -2
- package/src/components/TrendingPackagesCarousel.tsx +2 -2
- package/src/components/ViewPackagePage/components/important-files-view.tsx +18 -13
- package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +1 -0
- package/src/components/ViewPackagePage/components/sidebar-about-section.tsx +1 -0
- package/src/components/dialogs/GitHubRepositorySelector.tsx +123 -0
- package/src/components/dialogs/create-use-dialog.tsx +8 -2
- package/src/components/dialogs/edit-package-details-dialog.tsx +22 -3
- package/src/components/dialogs/view-ts-files-dialog.tsx +178 -33
- package/src/components/package-port/CodeAndPreview.tsx +4 -1
- package/src/components/package-port/CodeEditor.tsx +42 -35
- package/src/components/package-port/CodeEditorHeader.tsx +26 -20
- package/src/components/package-port/EditorNav.tsx +94 -37
- package/src/components/preview/BuildsList.tsx +238 -0
- package/src/components/preview/ConnectedRepoDashboard.tsx +258 -0
- package/src/components/preview/ConnectedRepoOverview.tsx +454 -0
- package/src/components/preview/ConnectedRepoSettings.tsx +343 -0
- package/src/components/preview/ConnectedReposCards.tsx +191 -0
- package/src/components/preview/index.tsx +207 -0
- package/src/components/ui/tree-view.tsx +23 -6
- package/src/hooks/use-axios.ts +2 -2
- package/src/hooks/use-create-release-dialog.ts +160 -0
- package/src/hooks/use-package-details-form.ts +7 -0
- package/src/hooks/use-packages-base-api-url.ts +1 -1
- package/src/hooks/use-sign-in.ts +2 -2
- package/src/hooks/useFileManagement.ts +22 -2
- package/src/index.css +4 -0
- package/src/lib/utils/formatTimeAgo.ts +10 -0
- package/src/lib/utils/isValidFileName.ts +15 -3
- package/src/pages/dashboard.tsx +2 -2
- package/src/pages/dev-login.tsx +2 -2
- package/src/pages/landing.tsx +1 -1
- package/src/pages/latest.tsx +2 -2
- package/src/pages/preview-build.tsx +380 -0
- package/src/pages/search.tsx +2 -2
- package/src/pages/trending.tsx +2 -2
- package/src/pages/user-profile.tsx +32 -24
- 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,7 +1077,18 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1073
1077
|
datasheet_pdf_urls: string[] | null;
|
|
1074
1078
|
ai_description: string | null;
|
|
1075
1079
|
}[];
|
|
1076
|
-
|
|
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
|
+
}[];
|
|
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;
|
|
1079
1094
|
getOrderFilesByOrderId: (orderId: string) => OrderFile[];
|
|
@@ -1121,6 +1136,7 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1121
1136
|
}) => Snippet | undefined;
|
|
1122
1137
|
searchSnippets: (query: string) => Snippet[];
|
|
1123
1138
|
searchPackages: (query: string) => Package[];
|
|
1139
|
+
searchAccounts: (query: string, limit?: number) => Account[];
|
|
1124
1140
|
deleteSnippet: (snippetId: string) => boolean;
|
|
1125
1141
|
addSession: (session: Omit<Session, "session_id">) => Session;
|
|
1126
1142
|
getSessions: ({ account_id, is_cli_session, }: {
|
|
@@ -1136,7 +1152,7 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1136
1152
|
addStar: (accountId: string, packageId: string) => AccountPackage;
|
|
1137
1153
|
removeStar: (accountId: string, packageId: string) => void;
|
|
1138
1154
|
hasStarred: (accountId: string, packageId: string) => boolean;
|
|
1139
|
-
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;
|
|
1140
1156
|
updatePackage: (packageId: string, updates: Partial<Package>) => Package | undefined;
|
|
1141
1157
|
getPackageById: (packageId: string) => Package | undefined;
|
|
1142
1158
|
getPackageReleaseById: (packageReleaseId: string) => PackageRelease | undefined;
|
|
@@ -1282,6 +1298,7 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1282
1298
|
creator_account_id: string;
|
|
1283
1299
|
owner_org_id: string;
|
|
1284
1300
|
owner_github_username: string | null;
|
|
1301
|
+
github_repo_full_name: string | null;
|
|
1285
1302
|
is_snippet: boolean;
|
|
1286
1303
|
is_board: boolean;
|
|
1287
1304
|
is_package: boolean;
|
|
@@ -1426,7 +1443,18 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1426
1443
|
datasheet_pdf_urls: string[] | null;
|
|
1427
1444
|
ai_description: string | null;
|
|
1428
1445
|
}[];
|
|
1429
|
-
|
|
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
|
+
}[];
|
|
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"> & {
|
|
1430
1458
|
addOrder: (order: Omit<Order, "order_id">) => Order;
|
|
1431
1459
|
getOrderById: (orderId: string) => Order | undefined;
|
|
1432
1460
|
getOrderFilesByOrderId: (orderId: string) => OrderFile[];
|
|
@@ -1474,6 +1502,7 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1474
1502
|
}) => Snippet | undefined;
|
|
1475
1503
|
searchSnippets: (query: string) => Snippet[];
|
|
1476
1504
|
searchPackages: (query: string) => Package[];
|
|
1505
|
+
searchAccounts: (query: string, limit?: number) => Account[];
|
|
1477
1506
|
deleteSnippet: (snippetId: string) => boolean;
|
|
1478
1507
|
addSession: (session: Omit<Session, "session_id">) => Session;
|
|
1479
1508
|
getSessions: ({ account_id, is_cli_session, }: {
|
|
@@ -1489,7 +1518,7 @@ declare const createDatabase: ({ seed }?: {
|
|
|
1489
1518
|
addStar: (accountId: string, packageId: string) => AccountPackage;
|
|
1490
1519
|
removeStar: (accountId: string, packageId: string) => void;
|
|
1491
1520
|
hasStarred: (accountId: string, packageId: string) => boolean;
|
|
1492
|
-
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;
|
|
1493
1522
|
updatePackage: (packageId: string, updates: Partial<Package>) => Package | undefined;
|
|
1494
1523
|
getPackageById: (packageId: string) => Package | undefined;
|
|
1495
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,
|
|
@@ -2798,6 +2814,31 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
|
|
|
2798
2814
|
];
|
|
2799
2815
|
return matchingPackages;
|
|
2800
2816
|
},
|
|
2817
|
+
searchAccounts: (query, limit) => {
|
|
2818
|
+
const state = get();
|
|
2819
|
+
const lowercaseQuery = query.toLowerCase();
|
|
2820
|
+
const accountsWithPublicPackages = /* @__PURE__ */ new Set();
|
|
2821
|
+
state.packages.filter((pkg) => pkg.is_public === true).forEach((pkg) => {
|
|
2822
|
+
if (pkg.creator_account_id) {
|
|
2823
|
+
accountsWithPublicPackages.add(pkg.creator_account_id);
|
|
2824
|
+
}
|
|
2825
|
+
if (pkg.owner_github_username) {
|
|
2826
|
+
const account = state.accounts.find(
|
|
2827
|
+
(acc) => acc.github_username === pkg.owner_github_username
|
|
2828
|
+
);
|
|
2829
|
+
if (account) {
|
|
2830
|
+
accountsWithPublicPackages.add(account.account_id);
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
const matchingAccounts = state.accounts.filter((account) => {
|
|
2835
|
+
if (!accountsWithPublicPackages.has(account.account_id)) {
|
|
2836
|
+
return false;
|
|
2837
|
+
}
|
|
2838
|
+
return account.github_username.toLowerCase().includes(lowercaseQuery);
|
|
2839
|
+
}).slice(0, limit || 50);
|
|
2840
|
+
return matchingAccounts;
|
|
2841
|
+
},
|
|
2801
2842
|
deleteSnippet: (snippetId) => {
|
|
2802
2843
|
let deleted = false;
|
|
2803
2844
|
set((state) => {
|
|
@@ -2956,6 +2997,7 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
|
|
|
2956
2997
|
const timestamp = Date.now();
|
|
2957
2998
|
const newPackage = {
|
|
2958
2999
|
package_id: `package_${timestamp}`,
|
|
3000
|
+
github_repo_full_name: null,
|
|
2959
3001
|
..._package
|
|
2960
3002
|
};
|
|
2961
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,
|
|
@@ -1019,6 +1020,38 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
|
|
|
1019
1020
|
|
|
1020
1021
|
return matchingPackages
|
|
1021
1022
|
},
|
|
1023
|
+
searchAccounts: (query: string, limit?: number): Account[] => {
|
|
1024
|
+
const state = get()
|
|
1025
|
+
const lowercaseQuery = query.toLowerCase()
|
|
1026
|
+
|
|
1027
|
+
const accountsWithPublicPackages = new Set<string>()
|
|
1028
|
+
state.packages
|
|
1029
|
+
.filter((pkg) => pkg.is_public === true)
|
|
1030
|
+
.forEach((pkg) => {
|
|
1031
|
+
if (pkg.creator_account_id) {
|
|
1032
|
+
accountsWithPublicPackages.add(pkg.creator_account_id)
|
|
1033
|
+
}
|
|
1034
|
+
if (pkg.owner_github_username) {
|
|
1035
|
+
const account = state.accounts.find(
|
|
1036
|
+
(acc) => acc.github_username === pkg.owner_github_username,
|
|
1037
|
+
)
|
|
1038
|
+
if (account) {
|
|
1039
|
+
accountsWithPublicPackages.add(account.account_id)
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
})
|
|
1043
|
+
|
|
1044
|
+
const matchingAccounts = state.accounts
|
|
1045
|
+
.filter((account) => {
|
|
1046
|
+
if (!accountsWithPublicPackages.has(account.account_id)) {
|
|
1047
|
+
return false
|
|
1048
|
+
}
|
|
1049
|
+
return account.github_username.toLowerCase().includes(lowercaseQuery)
|
|
1050
|
+
})
|
|
1051
|
+
.slice(0, limit || 50)
|
|
1052
|
+
|
|
1053
|
+
return matchingAccounts
|
|
1054
|
+
},
|
|
1022
1055
|
deleteSnippet: (snippetId: string): boolean => {
|
|
1023
1056
|
let deleted = false
|
|
1024
1057
|
set((state) => {
|
|
@@ -1193,11 +1226,15 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
|
|
|
1193
1226
|
)
|
|
1194
1227
|
},
|
|
1195
1228
|
addPackage: (
|
|
1196
|
-
_package: Omit<
|
|
1229
|
+
_package: Omit<
|
|
1230
|
+
z.input<typeof packageSchema>,
|
|
1231
|
+
"package_id" | "github_repo_full_name"
|
|
1232
|
+
>,
|
|
1197
1233
|
): Package => {
|
|
1198
1234
|
const timestamp = Date.now()
|
|
1199
1235
|
const newPackage = {
|
|
1200
1236
|
package_id: `package_${timestamp}`,
|
|
1237
|
+
github_repo_full_name: null,
|
|
1201
1238
|
..._package,
|
|
1202
1239
|
}
|
|
1203
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,20 @@
|
|
|
1
|
+
import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
import { accountSchema } from "fake-snippets-api/lib/db/schema"
|
|
4
|
+
|
|
5
|
+
export default withRouteSpec({
|
|
6
|
+
methods: ["POST"],
|
|
7
|
+
auth: "session",
|
|
8
|
+
jsonBody: z.object({
|
|
9
|
+
query: z.string(),
|
|
10
|
+
limit: z.number().optional().default(50),
|
|
11
|
+
}),
|
|
12
|
+
jsonResponse: z.object({
|
|
13
|
+
ok: z.boolean(),
|
|
14
|
+
accounts: z.array(accountSchema),
|
|
15
|
+
}),
|
|
16
|
+
})(async (req, ctx) => {
|
|
17
|
+
const { query, limit } = req.jsonBody
|
|
18
|
+
const accounts = ctx.db.searchAccounts(query, limit)
|
|
19
|
+
return ctx.json({ accounts, ok: true })
|
|
20
|
+
})
|
|
@@ -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
|
+
})
|