diff --git a/assets/openapi.json b/assets/openapi.json index 35b75a77..b78f33e5 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 39045b40..f9c26b66 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/package-lock.json b/package-lock.json index 563a9a4c..393aec42 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index c2f3536d..aeb54ea8 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "cheerio": "^1.0.0", "cookie-parser": "^1.4.7", "dotenv": "^16.4.5", + "email-providers": "^2.7.0", "exif-be-gone": "^1.5.1", "fast-zlib": "^2.0.1", "fido2-lib": "^3.5.3", diff --git a/src/api/routes/channels/#channel_id/directory-entries.ts b/src/api/routes/channels/#channel_id/directory-entries.ts new file mode 100644 index 00000000..da1ff90e --- /dev/null +++ b/src/api/routes/channels/#channel_id/directory-entries.ts @@ -0,0 +1,41 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import { route } from "@spacebar/api"; +import { HubDirectoryEntriesResponse } from "@spacebar/util"; +import { Request, Response, Router } from "express"; +const router = Router(); + +router.get( + "/", + route({ + responses: { + 200: { + body: "HubDirectoryEntriesResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + res.json([] as HubDirectoryEntriesResponse); + }, +); + +export default router; diff --git a/src/api/routes/guilds/automations/email-domain-lookup.ts b/src/api/routes/guilds/automations/email-domain-lookup.ts new file mode 100644 index 00000000..ebb76d7a --- /dev/null +++ b/src/api/routes/guilds/automations/email-domain-lookup.ts @@ -0,0 +1,105 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import { route } from "@spacebar/api"; +import { + EmailDomainLookupResponse, + EmailDomainLookupSchema, + EmailDomainLookupVerifyCodeSchema, + FieldErrors, +} from "@spacebar/util"; +import emailProviders from "email-providers/all.json"; +import { Request, Response, Router } from "express"; +import { HTTPError } from "lambert-server"; + +const router = Router(); + +router.post( + "/", + route({ + requestBody: "EmailDomainLookupSchema", + responses: { + 200: { + body: "EmailDomainLookupResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + const { email } = req.body as EmailDomainLookupSchema; + + const [_, tld] = email.split("@"); + + if (emailProviders.includes(tld.toLowerCase())) { + throw FieldErrors({ + name: { + message: + "That looks like a personal email address. Please use your official student email.", + code: "EMAIL_IS_UNOFFICIAL", + }, + }); + } + + return res.json({ + guilds_info: [], + has_matching_guild: false, + } as EmailDomainLookupResponse); + }, +); + +router.post( + "/verify-code", + route({ + requestBody: "EmailDomainLookupVerifyCodeSchema", + responses: { + // 200: { + // body: "EmailDomainLookupVerifyCodeResponse", + // }, + 400: { + body: "APIErrorResponse", + }, + 501: {}, + }, + }), + async (req: Request, res: Response) => { + const { email } = req.body as EmailDomainLookupVerifyCodeSchema; + + const [_, tld] = email.split("@"); + + if (emailProviders.includes(tld.toLowerCase())) { + throw FieldErrors({ + name: { + message: + "That looks like a personal email address. Please use your official student email.", + code: "EMAIL_IS_UNOFFICIAL", + }, + }); + } + + throw new HTTPError("Not implemented", 501); + + // return res.json({ + // guild: null, + // joined: false, + // } as EmailDomainLookupVerifyCodeResponse); + }, +); + +export default router; diff --git a/src/api/routes/hub-waitlist.ts b/src/api/routes/hub-waitlist.ts new file mode 100644 index 00000000..a6501e0e --- /dev/null +++ b/src/api/routes/hub-waitlist.ts @@ -0,0 +1,52 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import { route } from "@spacebar/api"; +import { + HubWaitlistSignupResponse, + HubWaitlistSignupSchema, +} from "@spacebar/util"; +import { Request, Response, Router } from "express"; +const router = Router(); + +router.post( + "/signup", + route({ + requestBody: "HubWaitlistSignupSchema", + responses: { + 200: { + body: "HubWaitlistSignupResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + const { email, school } = req.body as HubWaitlistSignupSchema; + + res.json({ + email, + email_domain: email.split("@")[1], + school, + user_id: req.user_id, + } as HubWaitlistSignupResponse); + }, +); + +export default router; diff --git a/src/util/schemas/EmailDomainLookupSchema.ts b/src/util/schemas/EmailDomainLookupSchema.ts new file mode 100644 index 00000000..43680aa4 --- /dev/null +++ b/src/util/schemas/EmailDomainLookupSchema.ts @@ -0,0 +1,24 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +export interface EmailDomainLookupSchema { + allow_multiple_guilds: boolean; + email: string; + use_verification_code: boolean; + guild_id?: string; +} diff --git a/src/util/schemas/EmailDomainLookupVerifyCodeSchema.ts b/src/util/schemas/EmailDomainLookupVerifyCodeSchema.ts new file mode 100644 index 00000000..9fe0bd46 --- /dev/null +++ b/src/util/schemas/EmailDomainLookupVerifyCodeSchema.ts @@ -0,0 +1,23 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +export interface EmailDomainLookupVerifyCodeSchema { + email: string; + guild_id: string; + code: string; +} diff --git a/src/util/schemas/HubWaitlistSignupSchema.ts b/src/util/schemas/HubWaitlistSignupSchema.ts new file mode 100644 index 00000000..8114b3d8 --- /dev/null +++ b/src/util/schemas/HubWaitlistSignupSchema.ts @@ -0,0 +1,22 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +export interface HubWaitlistSignupSchema { + email: string; + school: string; +} diff --git a/src/util/schemas/index.ts b/src/util/schemas/index.ts index 7d8abaa0..2972b1a5 100644 --- a/src/util/schemas/index.ts +++ b/src/util/schemas/index.ts @@ -34,6 +34,8 @@ export * from "./ConnectedAccountSchema"; export * from "./ConnectionCallbackSchema"; export * from "./ConnectionUpdateSchema"; export * from "./DmChannelCreateSchema"; +export * from "./EmailDomainLookupSchema"; +export * from "./EmailDomainLookupVerifyCodeSchema"; export * from "./EmojiCreateSchema"; export * from "./EmojiModifySchema"; export * from "./ForgotPasswordSchema"; @@ -42,6 +44,7 @@ export * from "./GuildCreateSchema"; export * from "./GuildTemplateCreateSchema"; export * from "./GuildUpdateSchema"; export * from "./GuildUpdateWelcomeScreenSchema"; +export * from "./HubWaitlistSignupSchema"; export * from "./IdentifySchema"; export * from "./InviteCreateSchema"; export * from "./LazyRequestSchema"; @@ -59,6 +62,7 @@ export * from "./RegisterSchema"; export * from "./RelationshipPostSchema"; export * from "./RelationshipPutSchema"; export * from "./RequestGuildMembersSchema"; +export * from "./responses"; export * from "./RoleModifySchema"; export * from "./RolePositionUpdateSchema"; export * from "./SelectProtocolSchema"; @@ -83,4 +87,3 @@ export * from "./WebAuthnSchema"; export * from "./WebhookCreateSchema"; export * from "./WebhookExecuteSchema"; export * from "./WidgetModifySchema"; -export * from "./responses"; diff --git a/src/util/schemas/responses/EmailDomainLookupResponse.ts b/src/util/schemas/responses/EmailDomainLookupResponse.ts new file mode 100644 index 00000000..dc7faa63 --- /dev/null +++ b/src/util/schemas/responses/EmailDomainLookupResponse.ts @@ -0,0 +1,27 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +export interface HubGuild { + icon: string; + id: string; + name: string; +} + +export interface EmailDomainLookupResponse { + guilds_info: HubGuild[]; + has_matching_guild: boolean; +} diff --git a/src/util/schemas/responses/EmailDomainLookupVerifyCodeResponse.ts b/src/util/schemas/responses/EmailDomainLookupVerifyCodeResponse.ts new file mode 100644 index 00000000..1fcfba34 --- /dev/null +++ b/src/util/schemas/responses/EmailDomainLookupVerifyCodeResponse.ts @@ -0,0 +1,24 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import { Guild } from "../../entities"; + +export interface EmailDomainLookupVerifyCodeResponse { + guild: Guild; + joined: boolean; +} diff --git a/src/util/schemas/responses/HubDirectoryEntriesResponse.ts b/src/util/schemas/responses/HubDirectoryEntriesResponse.ts new file mode 100644 index 00000000..9aaadfed --- /dev/null +++ b/src/util/schemas/responses/HubDirectoryEntriesResponse.ts @@ -0,0 +1,31 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import { Guild } from "../../entities"; + +export interface HubDirectoryEntry { + author_id: string; + created_at: string; + description: string; + directory_channel_id: string; + guild: Guild; + primary_category_id: number; + type: number; // TODO: not exactly sure what this is, channel type? +} + +export type HubDirectoryEntriesResponse = HubDirectoryEntry[]; diff --git a/src/util/schemas/responses/HubWaitlistSignupResponse.ts b/src/util/schemas/responses/HubWaitlistSignupResponse.ts new file mode 100644 index 00000000..bd11df22 --- /dev/null +++ b/src/util/schemas/responses/HubWaitlistSignupResponse.ts @@ -0,0 +1,24 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +export interface HubWaitlistSignupResponse { + email: string; + email_domain: string; + school: string; + user_id: string; +} diff --git a/src/util/schemas/responses/index.ts b/src/util/schemas/responses/index.ts index 070a2e55..d65c7404 100644 --- a/src/util/schemas/responses/index.ts +++ b/src/util/schemas/responses/index.ts @@ -21,6 +21,8 @@ export * from "./APIErrorResponse"; export * from "./BackupCodesChallengeResponse"; export * from "./CaptchaRequiredResponse"; export * from "./DiscoverableGuildsResponse"; +export * from "./EmailDomainLookupResponse"; +export * from "./EmailDomainLookupVerifyCodeResponse"; export * from "./GatewayBotResponse"; export * from "./GatewayResponse"; export * from "./GenerateRegistrationTokensResponse"; @@ -34,6 +36,8 @@ export * from "./GuildVanityUrl"; export * from "./GuildVoiceRegionsResponse"; export * from "./GuildWidgetJsonResponse"; export * from "./GuildWidgetSettingsResponse"; +export * from "./HubDirectoryEntriesResponse"; +export * from "./HubWaitlistSignupResponse"; export * from "./InstanceDomainsResponse"; export * from "./InstancePingResponse"; export * from "./InstanceStatsResponse"; @@ -47,7 +51,7 @@ export * from "./TypedResponses"; export * from "./UpdatesResponse"; export * from "./UserNoteResponse"; export * from "./UserProfileResponse"; -export * from "./UserRelationsResponse"; export * from "./UserRelationshipsResponse"; +export * from "./UserRelationsResponse"; export * from "./WebAuthnCreateResponse"; export * from "./WebhookCreateResponse";