@@ -8,8 +8,8 @@ import { notFound, orgNotFound, ServiceError } from "@/lib/serviceError";
88import { getOrgMetadata , isHttpError , isServiceError } from "@/lib/utils" ;
99import { prisma } from "@/prisma" ;
1010import { render } from "@react-email/components" ;
11- import { generateApiKey , getTokenFromConfig , hashSecret } from "@sourcebot/shared" ;
12- import { ApiKey , ConnectionSyncJobStatus , OrgRole , Prisma , RepoIndexingJobStatus , RepoIndexingJobType } from "@sourcebot/db" ;
11+ import { generateApiKey , getTokenFromConfig } from "@sourcebot/shared" ;
12+ import { ConnectionSyncJobStatus , OrgRole , Prisma , RepoIndexingJobStatus , RepoIndexingJobType } from "@sourcebot/db" ;
1313import { createLogger } from "@sourcebot/shared" ;
1414import { GiteaConnectionConfig } from "@sourcebot/schemas/v3/gitea.type" ;
1515import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type" ;
@@ -19,15 +19,14 @@ import { StatusCodes } from "http-status-codes";
1919import { cookies } from "next/headers" ;
2020import { createTransport } from "nodemailer" ;
2121import { Octokit } from "octokit" ;
22- import { getOrgFromDomain } from "./data/org" ;
2322import InviteUserEmail from "./emails/inviteUserEmail" ;
2423import JoinRequestApprovedEmail from "./emails/joinRequestApprovedEmail" ;
2524import JoinRequestSubmittedEmail from "./emails/joinRequestSubmittedEmail" ;
26- import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME , MOBILE_UNSUPPORTED_SPLASH_SCREEN_DISMISSED_COOKIE_NAME , SOURCEBOT_SUPPORT_EMAIL } from "./lib/constants" ;
27- import { ApiKeyPayload , RepositoryQuery } from "./lib/types" ;
25+ import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME , MOBILE_UNSUPPORTED_SPLASH_SCREEN_DISMISSED_COOKIE_NAME , SINGLE_TENANT_ORG_ID , SOURCEBOT_SUPPORT_EMAIL } from "./lib/constants" ;
26+ import { RepositoryQuery } from "./lib/types" ;
2827import { withAuth , withOptionalAuth , withAuth_skipOrgMembershipCheck } from "./middleware/withAuth" ;
2928import { withMinimumOrgRole } from "./middleware/withMinimumOrgRole" ;
30- import { getBrowsePath } from "./app/[domain] /browse/hooks/utils" ;
29+ import { getBrowsePath } from "./app/(app) /browse/hooks/utils" ;
3130import { sew } from "@/middleware/sew" ;
3231
3332const logger = createLogger ( 'web-actions' ) ;
@@ -48,59 +47,6 @@ export const completeOnboarding = async (): Promise<{ success: boolean } | Servi
4847 }
4948 } ) ) ;
5049
51- export const verifyApiKey = async ( apiKeyPayload : ApiKeyPayload ) : Promise < { apiKey : ApiKey } | ServiceError > => sew ( async ( ) => {
52- const parts = apiKeyPayload . apiKey . split ( "-" ) ;
53- if ( parts . length !== 2 || parts [ 0 ] !== "sourcebot" ) {
54- return {
55- statusCode : StatusCodes . BAD_REQUEST ,
56- errorCode : ErrorCode . INVALID_API_KEY ,
57- message : "Invalid API key" ,
58- } satisfies ServiceError ;
59- }
60-
61- const hash = hashSecret ( parts [ 1 ] )
62- const apiKey = await prisma . apiKey . findUnique ( {
63- where : {
64- hash,
65- } ,
66- } ) ;
67-
68- if ( ! apiKey ) {
69- return {
70- statusCode : StatusCodes . UNAUTHORIZED ,
71- errorCode : ErrorCode . INVALID_API_KEY ,
72- message : "Invalid API key" ,
73- } satisfies ServiceError ;
74- }
75-
76- const apiKeyTargetOrg = await prisma . org . findUnique ( {
77- where : {
78- domain : apiKeyPayload . domain ,
79- } ,
80- } ) ;
81-
82- if ( ! apiKeyTargetOrg ) {
83- return {
84- statusCode : StatusCodes . UNAUTHORIZED ,
85- errorCode : ErrorCode . INVALID_API_KEY ,
86- message : `Invalid API key payload. Provided domain ${ apiKeyPayload . domain } does not exist.` ,
87- } satisfies ServiceError ;
88- }
89-
90- if ( apiKey . orgId !== apiKeyTargetOrg . id ) {
91- return {
92- statusCode : StatusCodes . UNAUTHORIZED ,
93- errorCode : ErrorCode . INVALID_API_KEY ,
94- message : `Invalid API key payload. Provided domain ${ apiKeyPayload . domain } does not match the API key's org.` ,
95- } satisfies ServiceError ;
96- }
97-
98- return {
99- apiKey,
100- }
101- } ) ;
102-
103-
10450export const createApiKey = async ( name : string ) : Promise < { key : string } | ServiceError > => sew ( ( ) =>
10551 withAuth ( async ( { org, user, role, prisma } ) => {
10652 if ( ( env . DISABLE_API_KEY_CREATION_FOR_NON_OWNER_USERS === 'true' || env . DISABLE_API_KEY_USAGE_FOR_NON_OWNER_USERS === 'true' ) && role !== OrgRole . OWNER ) {
@@ -188,7 +134,7 @@ export const deleteApiKey = async (name: string): Promise<{ success: boolean } |
188134 type : "user"
189135 } ,
190136 target : {
191- id : org . domain ,
137+ id : org . id . toString ( ) ,
192138 type : "org"
193139 } ,
194140 orgId : org . id ,
@@ -600,7 +546,7 @@ export const createInvites = async (emails: string[]): Promise<{ success: boolea
600546 } ) ;
601547 }
602548
603- const hasAvailability = await orgHasAvailability ( org . domain ) ;
549+ const hasAvailability = await orgHasAvailability ( ) ;
604550 if ( ! hasAvailability ) {
605551 await auditService . createAudit ( {
606552 action : "user.invite_failed" ,
@@ -807,7 +753,6 @@ export const getMe = async () => sew(() =>
807753 memberships : userWithOrgs . orgs . map ( ( org ) => ( {
808754 id : org . orgId ,
809755 role : org . role ,
810- domain : org . org . domain ,
811756 name : org . org . name ,
812757 } ) )
813758 }
@@ -847,7 +792,7 @@ export const redeemInvite = async (inviteId: string): Promise<{ success: boolean
847792 }
848793
849794
850- const hasAvailability = await orgHasAvailability ( invite . org . domain ) ;
795+ const hasAvailability = await orgHasAvailability ( ) ;
851796 if ( ! hasAvailability ) {
852797 await failAuditCallback ( "Organization is at max capacity" ) ;
853798 return {
@@ -911,7 +856,6 @@ export const getInviteInfo = async (inviteId: string) => sew(() =>
911856 id : invite . id ,
912857 orgName : invite . org . name ,
913858 orgImageUrl : invite . org . imageUrl ?? undefined ,
914- orgDomain : invite . org . domain ,
915859 host : {
916860 name : invite . host . name ?? undefined ,
917861 email : invite . host . email ! ,
@@ -983,7 +927,7 @@ export const getOrgAccountRequests = async () => sew(() =>
983927 } ) ) ;
984928 } ) ) ;
985929
986- export const createAccountRequest = async ( userId : string , domain : string ) => sew ( async ( ) => {
930+ export const createAccountRequest = async ( userId : string ) => sew ( async ( ) => {
987931 const user = await prisma . user . findUnique ( {
988932 where : {
989933 id : userId ,
@@ -996,7 +940,7 @@ export const createAccountRequest = async (userId: string, domain: string) => se
996940
997941 const org = await prisma . org . findUnique ( {
998942 where : {
999- domain ,
943+ id : SINGLE_TENANT_ORG_ID ,
1000944 } ,
1001945 } ) ;
1002946
@@ -1057,7 +1001,6 @@ export const createAccountRequest = async (userId: string, domain: string) => se
10571001 avatarUrl : user . image ?? undefined ,
10581002 } ,
10591003 orgName : org . name ,
1060- orgDomain : org . domain ,
10611004 orgImageUrl : org . imageUrl ?? undefined ,
10621005 } ) ) ;
10631006
@@ -1086,10 +1029,10 @@ export const createAccountRequest = async (userId: string, domain: string) => se
10861029 }
10871030} ) ;
10881031
1089- export const getMemberApprovalRequired = async ( domain : string ) : Promise < boolean | ServiceError > => sew ( async ( ) => {
1032+ export const getMemberApprovalRequired = async ( ) : Promise < boolean | ServiceError > => sew ( async ( ) => {
10901033 const org = await prisma . org . findUnique ( {
10911034 where : {
1092- domain ,
1035+ id : SINGLE_TENANT_ORG_ID ,
10931036 } ,
10941037 } ) ;
10951038
@@ -1182,7 +1125,6 @@ export const approveAccountRequest = async (requestId: string) => sew(async () =
11821125 avatarUrl : request . requestedBy . image ?? undefined ,
11831126 } ,
11841127 orgName : org . name ,
1185- orgDomain : org . domain
11861128 } ) ) ;
11871129
11881130 const transport = createTransport ( smtpConnectionUrl ) ;
@@ -1191,7 +1133,7 @@ export const approveAccountRequest = async (requestId: string) => sew(async () =
11911133 from : env . EMAIL_FROM_ADDRESS ,
11921134 subject : `Your request to join ${ org . name } has been approved` ,
11931135 html,
1194- text : `Your request to join ${ org . name } on Sourcebot has been approved. You can now access the organization at ${ env . AUTH_URL } / ${ org . domain } ` ,
1136+ text : `Your request to join ${ org . name } on Sourcebot has been approved. You can now access the organization at ${ env . AUTH_URL } ` ,
11951137 } ) ;
11961138
11971139 const failed = result . rejected . concat ( result . pending ) . filter ( Boolean ) ;
@@ -1334,8 +1276,10 @@ export const getRepoImage = async (repoId: number): Promise<ArrayBuffer | Servic
13341276 } )
13351277} ) ;
13361278
1337- export const getAnonymousAccessStatus = async ( domain : string ) : Promise < boolean | ServiceError > => sew ( async ( ) => {
1338- const org = await getOrgFromDomain ( domain ) ;
1279+ export const getAnonymousAccessStatus = async ( ) : Promise < boolean | ServiceError > => sew ( async ( ) => {
1280+ const org = await prisma . org . findUnique ( {
1281+ where : { id : SINGLE_TENANT_ORG_ID } ,
1282+ } ) ;
13391283 if ( ! org ) {
13401284 return {
13411285 statusCode : StatusCodes . NOT_FOUND ,
0 commit comments