@tscircuit/fake-snippets 0.0.110 → 0.0.111

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 (32) hide show
  1. package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +1 -0
  2. package/bun-tests/fake-snippets-api/routes/orgs/create.test.ts +2 -2
  3. package/bun-tests/fake-snippets-api/routes/orgs/update.test.ts +52 -0
  4. package/bun.lock +14 -2
  5. package/dist/bundle.js +81 -36
  6. package/dist/index.d.ts +33 -13
  7. package/dist/index.js +10 -6
  8. package/dist/schema.d.ts +24 -8
  9. package/dist/schema.js +5 -3
  10. package/fake-snippets-api/lib/db/db-client.ts +7 -3
  11. package/fake-snippets-api/lib/db/schema.ts +3 -2
  12. package/fake-snippets-api/lib/middleware/with-session-auth.ts +59 -7
  13. package/fake-snippets-api/lib/public-mapping/public-map-org.ts +3 -2
  14. package/fake-snippets-api/routes/api/orgs/create.ts +4 -2
  15. package/fake-snippets-api/routes/api/orgs/get.ts +1 -1
  16. package/fake-snippets-api/routes/api/orgs/list_members.ts +1 -8
  17. package/fake-snippets-api/routes/api/orgs/update.ts +31 -6
  18. package/fake-snippets-api/routes/api/packages/create.ts +5 -2
  19. package/package.json +6 -4
  20. package/src/App.tsx +3 -5
  21. package/src/components/DownloadButtonAndMenu.tsx +14 -1
  22. package/src/components/SentryNotFoundReporter.tsx +44 -0
  23. package/src/components/organization/OrganizationCard.tsx +5 -3
  24. package/src/hooks/use-hydration.ts +30 -0
  25. package/src/hooks/use-org-by-github-handle.ts +1 -1
  26. package/src/lib/download-fns/download-kicad-files.ts +10 -0
  27. package/src/lib/download-fns/download-step.ts +12 -0
  28. package/src/pages/create-organization.tsx +1 -0
  29. package/src/pages/organization-settings.tsx +4 -1
  30. package/src/pages/search.tsx +7 -2
  31. package/src/pages/user-settings.tsx +161 -0
  32. package/src/pages/view-package.tsx +23 -3
package/dist/index.d.ts CHANGED
@@ -151,9 +151,11 @@ declare const accountSchema: z.ZodObject<{
151
151
  apartment?: string | undefined;
152
152
  }>>;
153
153
  personal_org_id: z.ZodOptional<z.ZodString>;
154
+ is_tscircuit_staff: z.ZodDefault<z.ZodBoolean>;
154
155
  }, "strip", z.ZodTypeAny, {
155
156
  account_id: string;
156
157
  github_username: string;
158
+ is_tscircuit_staff: boolean;
157
159
  shippingInfo?: {
158
160
  firstName: string;
159
161
  lastName: string;
@@ -183,6 +185,7 @@ declare const accountSchema: z.ZodObject<{
183
185
  apartment?: string | undefined;
184
186
  } | undefined;
185
187
  personal_org_id?: string | undefined;
188
+ is_tscircuit_staff?: boolean | undefined;
186
189
  }>;
187
190
  type Account = z.infer<typeof accountSchema>;
188
191
  declare const orderSchema: z.ZodObject<{
@@ -945,23 +948,26 @@ declare const packageBuildSchema: z.ZodObject<{
945
948
  type PackageBuild = z.infer<typeof packageBuildSchema>;
946
949
  declare const orgSchema: z.ZodObject<{
947
950
  org_id: z.ZodString;
948
- github_handle: z.ZodString;
951
+ github_handle: z.ZodOptional<z.ZodString>;
949
952
  owner_account_id: z.ZodString;
950
953
  is_personal_org: z.ZodDefault<z.ZodBoolean>;
951
954
  created_at: z.ZodString;
952
955
  org_display_name: z.ZodOptional<z.ZodString>;
956
+ org_name: z.ZodString;
953
957
  }, "strip", z.ZodTypeAny, {
954
958
  created_at: string;
955
959
  org_id: string;
956
- github_handle: string;
957
960
  owner_account_id: string;
958
961
  is_personal_org: boolean;
962
+ org_name: string;
963
+ github_handle?: string | undefined;
959
964
  org_display_name?: string | undefined;
960
965
  }, {
961
966
  created_at: string;
962
967
  org_id: string;
963
- github_handle: string;
964
968
  owner_account_id: string;
969
+ org_name: string;
970
+ github_handle?: string | undefined;
965
971
  is_personal_org?: boolean | undefined;
966
972
  org_display_name?: string | undefined;
967
973
  }>;
@@ -1091,6 +1097,7 @@ declare const createDatabase: ({ seed }?: {
1091
1097
  accounts: {
1092
1098
  account_id: string;
1093
1099
  github_username: string;
1100
+ is_tscircuit_staff: boolean;
1094
1101
  shippingInfo?: {
1095
1102
  firstName: string;
1096
1103
  lastName: string;
@@ -1158,9 +1165,10 @@ declare const createDatabase: ({ seed }?: {
1158
1165
  organizations: {
1159
1166
  created_at: string;
1160
1167
  org_id: string;
1161
- github_handle: string;
1162
1168
  owner_account_id: string;
1163
1169
  is_personal_org: boolean;
1170
+ org_name: string;
1171
+ github_handle?: string | undefined;
1164
1172
  org_display_name?: string | undefined;
1165
1173
  }[];
1166
1174
  orgAccounts: {
@@ -1338,7 +1346,8 @@ declare const createDatabase: ({ seed }?: {
1338
1346
  updateJlcpcbOrderState: (orderId: string, updates: Partial<JlcpcbOrderState>) => void;
1339
1347
  addOrderFile: (orderFile: Omit<OrderFile, "order_file_id">) => OrderFile;
1340
1348
  getOrderFileById: (orderFileId: string) => OrderFile | undefined;
1341
- addAccount: (account: Omit<Account, "account_id"> & Partial<Pick<Account, "account_id">>) => {
1349
+ addAccount: (account: Omit<Account, "account_id" | "is_tscircuit_staff"> & Partial<Pick<Account, "account_id" | "is_tscircuit_staff">>) => {
1350
+ is_tscircuit_staff: boolean;
1342
1351
  github_username: string;
1343
1352
  shippingInfo?: {
1344
1353
  firstName: string;
@@ -1430,12 +1439,14 @@ declare const createDatabase: ({ seed }?: {
1430
1439
  org_id?: string;
1431
1440
  is_personal_org?: boolean;
1432
1441
  owner_account_id: string;
1442
+ github_handle?: string;
1433
1443
  }) => {
1434
1444
  created_at: string;
1435
1445
  org_id: string;
1436
- github_handle: string;
1437
1446
  owner_account_id: string;
1438
1447
  is_personal_org: boolean;
1448
+ org_name: string;
1449
+ github_handle?: string | undefined;
1439
1450
  org_display_name?: string | undefined;
1440
1451
  };
1441
1452
  getOrgs: (filters?: {
@@ -1450,9 +1461,10 @@ declare const createDatabase: ({ seed }?: {
1450
1461
  can_manage_org: boolean;
1451
1462
  created_at: string;
1452
1463
  org_id: string;
1453
- github_handle: string;
1454
1464
  owner_account_id: string;
1455
1465
  is_personal_org: boolean;
1466
+ org_name: string;
1467
+ github_handle?: string | undefined;
1456
1468
  org_display_name?: string | undefined;
1457
1469
  }[];
1458
1470
  getOrg: (filters: {
@@ -1467,9 +1479,10 @@ declare const createDatabase: ({ seed }?: {
1467
1479
  can_manage_org: boolean;
1468
1480
  created_at: string;
1469
1481
  org_id: string;
1470
- github_handle: string;
1471
1482
  owner_account_id: string;
1472
1483
  is_personal_org: boolean;
1484
+ org_name: string;
1485
+ github_handle?: string | undefined;
1473
1486
  org_display_name?: string | undefined;
1474
1487
  } | null;
1475
1488
  addOrganizationAccount: (organizationAccount: {
@@ -1598,6 +1611,7 @@ declare const createDatabase: ({ seed }?: {
1598
1611
  accounts: {
1599
1612
  account_id: string;
1600
1613
  github_username: string;
1614
+ is_tscircuit_staff: boolean;
1601
1615
  shippingInfo?: {
1602
1616
  firstName: string;
1603
1617
  lastName: string;
@@ -1665,9 +1679,10 @@ declare const createDatabase: ({ seed }?: {
1665
1679
  organizations: {
1666
1680
  created_at: string;
1667
1681
  org_id: string;
1668
- github_handle: string;
1669
1682
  owner_account_id: string;
1670
1683
  is_personal_org: boolean;
1684
+ org_name: string;
1685
+ github_handle?: string | undefined;
1671
1686
  org_display_name?: string | undefined;
1672
1687
  }[];
1673
1688
  orgAccounts: {
@@ -1845,7 +1860,8 @@ declare const createDatabase: ({ seed }?: {
1845
1860
  updateJlcpcbOrderState: (orderId: string, updates: Partial<JlcpcbOrderState>) => void;
1846
1861
  addOrderFile: (orderFile: Omit<OrderFile, "order_file_id">) => OrderFile;
1847
1862
  getOrderFileById: (orderFileId: string) => OrderFile | undefined;
1848
- addAccount: (account: Omit<Account, "account_id"> & Partial<Pick<Account, "account_id">>) => {
1863
+ addAccount: (account: Omit<Account, "account_id" | "is_tscircuit_staff"> & Partial<Pick<Account, "account_id" | "is_tscircuit_staff">>) => {
1864
+ is_tscircuit_staff: boolean;
1849
1865
  github_username: string;
1850
1866
  shippingInfo?: {
1851
1867
  firstName: string;
@@ -1937,12 +1953,14 @@ declare const createDatabase: ({ seed }?: {
1937
1953
  org_id?: string;
1938
1954
  is_personal_org?: boolean;
1939
1955
  owner_account_id: string;
1956
+ github_handle?: string;
1940
1957
  }) => {
1941
1958
  created_at: string;
1942
1959
  org_id: string;
1943
- github_handle: string;
1944
1960
  owner_account_id: string;
1945
1961
  is_personal_org: boolean;
1962
+ org_name: string;
1963
+ github_handle?: string | undefined;
1946
1964
  org_display_name?: string | undefined;
1947
1965
  };
1948
1966
  getOrgs: (filters?: {
@@ -1957,9 +1975,10 @@ declare const createDatabase: ({ seed }?: {
1957
1975
  can_manage_org: boolean;
1958
1976
  created_at: string;
1959
1977
  org_id: string;
1960
- github_handle: string;
1961
1978
  owner_account_id: string;
1962
1979
  is_personal_org: boolean;
1980
+ org_name: string;
1981
+ github_handle?: string | undefined;
1963
1982
  org_display_name?: string | undefined;
1964
1983
  }[];
1965
1984
  getOrg: (filters: {
@@ -1974,9 +1993,10 @@ declare const createDatabase: ({ seed }?: {
1974
1993
  can_manage_org: boolean;
1975
1994
  created_at: string;
1976
1995
  org_id: string;
1977
- github_handle: string;
1978
1996
  owner_account_id: string;
1979
1997
  is_personal_org: boolean;
1998
+ org_name: string;
1999
+ github_handle?: string | undefined;
1980
2000
  org_display_name?: string | undefined;
1981
2001
  } | null;
1982
2002
  addOrganizationAccount: (organizationAccount: {
package/dist/index.js CHANGED
@@ -66,7 +66,8 @@ var accountSchema = z.object({
66
66
  account_id: z.string(),
67
67
  github_username: z.string(),
68
68
  shippingInfo: shippingInfoSchema.optional(),
69
- personal_org_id: z.string().optional()
69
+ personal_org_id: z.string().optional(),
70
+ is_tscircuit_staff: z.boolean().default(false)
70
71
  });
71
72
  var orderSchema = z.object({
72
73
  order_id: z.string(),
@@ -336,11 +337,12 @@ var packageBuildSchema = z.object({
336
337
  });
337
338
  var orgSchema = z.object({
338
339
  org_id: z.string(),
339
- github_handle: z.string(),
340
+ github_handle: z.string().optional(),
340
341
  owner_account_id: z.string(),
341
342
  is_personal_org: z.boolean().default(false),
342
343
  created_at: z.string().datetime(),
343
- org_display_name: z.string().optional()
344
+ org_display_name: z.string().optional(),
345
+ org_name: z.string()
344
346
  });
345
347
  var orgAccountSchema = z.object({
346
348
  org_account_id: z.string(),
@@ -2503,7 +2505,8 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
2503
2505
  addAccount: (account) => {
2504
2506
  const newAccount = {
2505
2507
  account_id: account.account_id || `account_${get().idCounter + 1}`,
2506
- ...account
2508
+ ...account,
2509
+ is_tscircuit_staff: Boolean(account.is_tscircuit_staff)
2507
2510
  };
2508
2511
  set((state) => {
2509
2512
  return {
@@ -3551,8 +3554,9 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
3551
3554
  },
3552
3555
  addOrganization: (organization) => {
3553
3556
  const newOrganization = {
3557
+ org_name: organization.name,
3554
3558
  org_id: organization.org_id || `org_${get().idCounter + 1}`,
3555
- github_handle: organization.name,
3559
+ github_handle: organization.github_handle,
3556
3560
  is_personal_org: organization.is_personal_org || false,
3557
3561
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
3558
3562
  ...organization
@@ -3607,7 +3611,7 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
3607
3611
  orgs = orgs.filter((org2) => org2.org_id === filters.org_id);
3608
3612
  }
3609
3613
  if (filters?.org_name) {
3610
- orgs = orgs.filter((org2) => org2.github_handle === filters.org_name);
3614
+ orgs = orgs.filter((org2) => org2.org_name === filters.org_name);
3611
3615
  }
3612
3616
  if (filters?.github_handle) {
3613
3617
  orgs = orgs.filter((org2) => org2.github_handle === filters.github_handle);
package/dist/schema.d.ts CHANGED
@@ -219,9 +219,11 @@ declare const accountSchema: z.ZodObject<{
219
219
  apartment?: string | undefined;
220
220
  }>>;
221
221
  personal_org_id: z.ZodOptional<z.ZodString>;
222
+ is_tscircuit_staff: z.ZodDefault<z.ZodBoolean>;
222
223
  }, "strip", z.ZodTypeAny, {
223
224
  account_id: string;
224
225
  github_username: string;
226
+ is_tscircuit_staff: boolean;
225
227
  shippingInfo?: {
226
228
  firstName: string;
227
229
  lastName: string;
@@ -251,6 +253,7 @@ declare const accountSchema: z.ZodObject<{
251
253
  apartment?: string | undefined;
252
254
  } | undefined;
253
255
  personal_org_id?: string | undefined;
256
+ is_tscircuit_staff?: boolean | undefined;
254
257
  }>;
255
258
  type Account = z.infer<typeof accountSchema>;
256
259
  declare const orderSchema: z.ZodObject<{
@@ -1118,23 +1121,26 @@ declare const packageBuildSchema: z.ZodObject<{
1118
1121
  type PackageBuild = z.infer<typeof packageBuildSchema>;
1119
1122
  declare const orgSchema: z.ZodObject<{
1120
1123
  org_id: z.ZodString;
1121
- github_handle: z.ZodString;
1124
+ github_handle: z.ZodOptional<z.ZodString>;
1122
1125
  owner_account_id: z.ZodString;
1123
1126
  is_personal_org: z.ZodDefault<z.ZodBoolean>;
1124
1127
  created_at: z.ZodString;
1125
1128
  org_display_name: z.ZodOptional<z.ZodString>;
1129
+ org_name: z.ZodString;
1126
1130
  }, "strip", z.ZodTypeAny, {
1127
1131
  created_at: string;
1128
1132
  org_id: string;
1129
- github_handle: string;
1130
1133
  owner_account_id: string;
1131
1134
  is_personal_org: boolean;
1135
+ org_name: string;
1136
+ github_handle?: string | undefined;
1132
1137
  org_display_name?: string | undefined;
1133
1138
  }, {
1134
1139
  created_at: string;
1135
1140
  org_id: string;
1136
- github_handle: string;
1137
1141
  owner_account_id: string;
1142
+ org_name: string;
1143
+ github_handle?: string | undefined;
1138
1144
  is_personal_org?: boolean | undefined;
1139
1145
  org_display_name?: string | undefined;
1140
1146
  }>;
@@ -1527,9 +1533,11 @@ declare const databaseSchema: z.ZodObject<{
1527
1533
  apartment?: string | undefined;
1528
1534
  }>>;
1529
1535
  personal_org_id: z.ZodOptional<z.ZodString>;
1536
+ is_tscircuit_staff: z.ZodDefault<z.ZodBoolean>;
1530
1537
  }, "strip", z.ZodTypeAny, {
1531
1538
  account_id: string;
1532
1539
  github_username: string;
1540
+ is_tscircuit_staff: boolean;
1533
1541
  shippingInfo?: {
1534
1542
  firstName: string;
1535
1543
  lastName: string;
@@ -1559,6 +1567,7 @@ declare const databaseSchema: z.ZodObject<{
1559
1567
  apartment?: string | undefined;
1560
1568
  } | undefined;
1561
1569
  personal_org_id?: string | undefined;
1570
+ is_tscircuit_staff?: boolean | undefined;
1562
1571
  }>, "many">>;
1563
1572
  packages: z.ZodDefault<z.ZodArray<z.ZodObject<{
1564
1573
  package_id: z.ZodString;
@@ -1714,23 +1723,26 @@ declare const databaseSchema: z.ZodObject<{
1714
1723
  }>, "many">>;
1715
1724
  organizations: z.ZodDefault<z.ZodArray<z.ZodObject<{
1716
1725
  org_id: z.ZodString;
1717
- github_handle: z.ZodString;
1726
+ github_handle: z.ZodOptional<z.ZodString>;
1718
1727
  owner_account_id: z.ZodString;
1719
1728
  is_personal_org: z.ZodDefault<z.ZodBoolean>;
1720
1729
  created_at: z.ZodString;
1721
1730
  org_display_name: z.ZodOptional<z.ZodString>;
1731
+ org_name: z.ZodString;
1722
1732
  }, "strip", z.ZodTypeAny, {
1723
1733
  created_at: string;
1724
1734
  org_id: string;
1725
- github_handle: string;
1726
1735
  owner_account_id: string;
1727
1736
  is_personal_org: boolean;
1737
+ org_name: string;
1738
+ github_handle?: string | undefined;
1728
1739
  org_display_name?: string | undefined;
1729
1740
  }, {
1730
1741
  created_at: string;
1731
1742
  org_id: string;
1732
- github_handle: string;
1733
1743
  owner_account_id: string;
1744
+ org_name: string;
1745
+ github_handle?: string | undefined;
1734
1746
  is_personal_org?: boolean | undefined;
1735
1747
  org_display_name?: string | undefined;
1736
1748
  }>, "many">>;
@@ -2326,6 +2338,7 @@ declare const databaseSchema: z.ZodObject<{
2326
2338
  accounts: {
2327
2339
  account_id: string;
2328
2340
  github_username: string;
2341
+ is_tscircuit_staff: boolean;
2329
2342
  shippingInfo?: {
2330
2343
  firstName: string;
2331
2344
  lastName: string;
@@ -2393,9 +2406,10 @@ declare const databaseSchema: z.ZodObject<{
2393
2406
  organizations: {
2394
2407
  created_at: string;
2395
2408
  org_id: string;
2396
- github_handle: string;
2397
2409
  owner_account_id: string;
2398
2410
  is_personal_org: boolean;
2411
+ org_name: string;
2412
+ github_handle?: string | undefined;
2399
2413
  org_display_name?: string | undefined;
2400
2414
  }[];
2401
2415
  orgAccounts: {
@@ -2671,6 +2685,7 @@ declare const databaseSchema: z.ZodObject<{
2671
2685
  apartment?: string | undefined;
2672
2686
  } | undefined;
2673
2687
  personal_org_id?: string | undefined;
2688
+ is_tscircuit_staff?: boolean | undefined;
2674
2689
  }[] | undefined;
2675
2690
  packages?: {
2676
2691
  name: string;
@@ -2725,8 +2740,9 @@ declare const databaseSchema: z.ZodObject<{
2725
2740
  organizations?: {
2726
2741
  created_at: string;
2727
2742
  org_id: string;
2728
- github_handle: string;
2729
2743
  owner_account_id: string;
2744
+ org_name: string;
2745
+ github_handle?: string | undefined;
2730
2746
  is_personal_org?: boolean | undefined;
2731
2747
  org_display_name?: string | undefined;
2732
2748
  }[] | undefined;
package/dist/schema.js CHANGED
@@ -61,7 +61,8 @@ var accountSchema = z.object({
61
61
  account_id: z.string(),
62
62
  github_username: z.string(),
63
63
  shippingInfo: shippingInfoSchema.optional(),
64
- personal_org_id: z.string().optional()
64
+ personal_org_id: z.string().optional(),
65
+ is_tscircuit_staff: z.boolean().default(false)
65
66
  });
66
67
  var orderSchema = z.object({
67
68
  order_id: z.string(),
@@ -331,11 +332,12 @@ var packageBuildSchema = z.object({
331
332
  });
332
333
  var orgSchema = z.object({
333
334
  org_id: z.string(),
334
- github_handle: z.string(),
335
+ github_handle: z.string().optional(),
335
336
  owner_account_id: z.string(),
336
337
  is_personal_org: z.boolean().default(false),
337
338
  created_at: z.string().datetime(),
338
- org_display_name: z.string().optional()
339
+ org_display_name: z.string().optional(),
340
+ org_name: z.string()
339
341
  });
340
342
  var orgAccountSchema = z.object({
341
343
  org_account_id: z.string(),
@@ -178,11 +178,13 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
178
178
  return state.orderFiles.find((file) => file.order_file_id === orderFileId)
179
179
  },
180
180
  addAccount: (
181
- account: Omit<Account, "account_id"> & Partial<Pick<Account, "account_id">>,
181
+ account: Omit<Account, "account_id" | "is_tscircuit_staff"> &
182
+ Partial<Pick<Account, "account_id" | "is_tscircuit_staff">>,
182
183
  ) => {
183
184
  const newAccount = {
184
185
  account_id: account.account_id || `account_${get().idCounter + 1}`,
185
186
  ...account,
187
+ is_tscircuit_staff: Boolean(account.is_tscircuit_staff),
186
188
  }
187
189
 
188
190
  set((state) => {
@@ -1549,10 +1551,12 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
1549
1551
  org_id?: string
1550
1552
  is_personal_org?: boolean
1551
1553
  owner_account_id: string
1554
+ github_handle?: string
1552
1555
  }) => {
1553
1556
  const newOrganization: Organization = {
1557
+ org_name: organization.name,
1554
1558
  org_id: organization.org_id || `org_${get().idCounter + 1}`,
1555
- github_handle: organization.name,
1559
+ github_handle: organization.github_handle,
1556
1560
  is_personal_org: organization.is_personal_org || false,
1557
1561
  created_at: new Date().toISOString(),
1558
1562
  ...organization,
@@ -1630,7 +1634,7 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
1630
1634
  orgs = orgs.filter((org) => org.org_id === filters.org_id)
1631
1635
  }
1632
1636
  if (filters?.org_name) {
1633
- orgs = orgs.filter((org) => org.github_handle === filters.org_name)
1637
+ orgs = orgs.filter((org) => org.org_name === filters.org_name)
1634
1638
  }
1635
1639
  // if (filters?.org_name && auth?.account_id) {
1636
1640
  // const account = get().accounts.find(x => x.account_id == auth?.account_id)
@@ -67,12 +67,12 @@ export const shippingInfoSchema = z.object({
67
67
  country: z.string(),
68
68
  phone: z.string(),
69
69
  })
70
-
71
70
  export const accountSchema = z.object({
72
71
  account_id: z.string(),
73
72
  github_username: z.string(),
74
73
  shippingInfo: shippingInfoSchema.optional(),
75
74
  personal_org_id: z.string().optional(),
75
+ is_tscircuit_staff: z.boolean().default(false),
76
76
  })
77
77
  export type Account = z.infer<typeof accountSchema>
78
78
 
@@ -401,11 +401,12 @@ export type PackageBuild = z.infer<typeof packageBuildSchema>
401
401
 
402
402
  export const orgSchema = z.object({
403
403
  org_id: z.string(),
404
- github_handle: z.string(),
404
+ github_handle: z.string().optional(),
405
405
  owner_account_id: z.string(),
406
406
  is_personal_org: z.boolean().default(false),
407
407
  created_at: z.string().datetime(),
408
408
  org_display_name: z.string().optional(),
409
+ org_name: z.string(),
409
410
  })
410
411
  export type Organization = z.infer<typeof orgSchema>
411
412
 
@@ -1,10 +1,11 @@
1
1
  import type { Middleware } from "winterspec/middleware"
2
2
  import type { CtxErrorFn } from "./with-ctx-error"
3
+ import type { DbClient } from "../db/db-client"
3
4
 
4
5
  export const withSessionAuth: Middleware<
5
6
  {
6
7
  error: CtxErrorFn
7
- db: any
8
+ db: DbClient
8
9
  },
9
10
  {
10
11
  auth: {
@@ -13,6 +14,13 @@ export const withSessionAuth: Middleware<
13
14
  personal_org_id: string
14
15
  github_username: string
15
16
  session_id: string
17
+ orgs: Array<{
18
+ org_id: string
19
+ name: string
20
+ user_permissions: {
21
+ can_manage_packages: boolean
22
+ }
23
+ }>
16
24
  }
17
25
  },
18
26
  {}
@@ -22,28 +30,72 @@ export const withSessionAuth: Middleware<
22
30
  const token = req.headers.get("authorization")?.split("Bearer ")?.[1]
23
31
 
24
32
  // Only check database accounts when we're in a Bun test environment
25
- if (process.env.BUN_TEST === "true" && ctx.db?.accounts) {
26
- const account = ctx.db.accounts.find((acc: any) => acc.account_id === token)
27
-
33
+ if (process.env.BUN_TEST === "true" && ctx.db?.getState) {
34
+ const state = ctx.db.getState()
35
+ const account = state.accounts.find((acc: any) => acc.account_id === token)
28
36
  if (account) {
37
+ // Fetch orgs for this account
38
+ const orgAccounts = state.orgAccounts.filter(
39
+ (oa: any) => oa.account_id === account.account_id,
40
+ )
41
+
42
+ const orgs = orgAccounts.map((oa: any) => {
43
+ const org = state.organizations.find((o: any) => o.org_id === oa.org_id)
44
+ return {
45
+ org_id: oa.org_id,
46
+ name:
47
+ org?.org_display_name ||
48
+ org?.org_name ||
49
+ org?.github_handle ||
50
+ oa.org_id,
51
+ user_permissions: { can_manage_packages: true },
52
+ }
53
+ })
54
+
29
55
  ctx.auth = {
30
56
  type: "session",
31
57
  account_id: account.account_id,
32
58
  personal_org_id: account.personal_org_id || `org-${account.account_id}`,
33
59
  github_username: account.github_username,
34
60
  session_id: `session-${account.account_id}`,
61
+ orgs:
62
+ orgs.length > 0
63
+ ? orgs
64
+ : [
65
+ {
66
+ org_id:
67
+ account.personal_org_id || `org-${account.account_id}`,
68
+ name:
69
+ account.github_username ||
70
+ account.personal_org_id ||
71
+ `org-${account.account_id}`,
72
+ user_permissions: { can_manage_packages: true },
73
+ },
74
+ ],
35
75
  }
36
76
  return next(req, ctx)
37
77
  }
38
78
  }
39
79
 
40
- // For all other environments or if account not found in test, use hardcoded auth
80
+ // Fallback auth for non-test environments or when no token is found
81
+ const fallbackAccountId = "account-1234"
82
+ const fallbackOrgId = "org-1234"
83
+
84
+ const fallbackOrgs = [
85
+ {
86
+ org_id: fallbackOrgId,
87
+ name: "org-1234",
88
+ user_permissions: { can_manage_packages: true },
89
+ },
90
+ ]
91
+
41
92
  ctx.auth = {
42
93
  type: "session",
43
- account_id: "account-1234",
44
- personal_org_id: "org-1234",
94
+ account_id: fallbackAccountId,
95
+ personal_org_id: fallbackOrgId,
45
96
  github_username: "testuser",
46
97
  session_id: "session-1234",
98
+ orgs: fallbackOrgs,
47
99
  }
48
100
 
49
101
  return next(req, ctx)
@@ -16,13 +16,14 @@ export const publicMapOrg = (
16
16
  created_at,
17
17
  is_personal_org,
18
18
  org_display_name,
19
+ org_name,
19
20
  ...org
20
21
  } = internal_org
21
22
  return {
22
23
  org_id: org.org_id,
23
- display_name: org_display_name ?? github_handle ?? "",
24
+ display_name: org_display_name ?? org_name,
24
25
  owner_account_id: org.owner_account_id,
25
- name: github_handle,
26
+ name: org_name,
26
27
  member_count: Number(member_count) || 0,
27
28
  package_count: Number(package_count) || 0,
28
29
  is_personal_org: Boolean(is_personal_org),
@@ -7,15 +7,16 @@ export default withRouteSpec({
7
7
  methods: ["GET", "POST"],
8
8
  commonParams: z.object({
9
9
  name: z.string(),
10
+ github_handle: z.string().optional(),
10
11
  }),
11
12
  auth: "session",
12
13
  jsonResponse: z.object({
13
14
  org: publicOrgSchema,
14
15
  }),
15
16
  })(async (req, ctx) => {
16
- const { name } = req.commonParams
17
+ const { name, github_handle } = req.commonParams
17
18
 
18
- const existing = ctx.db.getOrg({ github_handle: name })
19
+ const existing = ctx.db.getOrg({ org_name: name })
19
20
 
20
21
  if (existing) {
21
22
  return ctx.error(400, {
@@ -28,6 +29,7 @@ export default withRouteSpec({
28
29
  name: name,
29
30
  created_at: new Date(),
30
31
  can_manage_org: true,
32
+ ...(github_handle ? { github_handle } : {}),
31
33
  }
32
34
 
33
35
  const org = ctx.db.addOrganization(newOrg)
@@ -9,7 +9,7 @@ export default withRouteSpec({
9
9
  .object({ org_id: z.string() })
10
10
  .or(z.object({ org_name: z.string() }))
11
11
  .or(z.object({ github_handle: z.string() })),
12
- auth: "session",
12
+ auth: "optional_session",
13
13
  jsonResponse: z.object({
14
14
  org: publicOrgSchema,
15
15
  }),
@@ -13,7 +13,7 @@ export default withRouteSpec({
13
13
  name: z.string(),
14
14
  }),
15
15
  ),
16
- auth: "session",
16
+ auth: "optional_session",
17
17
  jsonResponse: z.object({
18
18
  members: z.array(accountSchema),
19
19
  }),
@@ -35,13 +35,6 @@ export default withRouteSpec({
35
35
  })
36
36
  }
37
37
 
38
- if (!org.can_manage_org) {
39
- return ctx.error(403, {
40
- error_code: "not_authorized",
41
- message: "You do not have permission to manage this organization",
42
- })
43
- }
44
-
45
38
  const members = ctx.db.orgAccounts
46
39
  .map((m) => {
47
40
  if (m.org_id == org.org_id) return ctx.db.getAccount(m.account_id)