diff options
-rw-r--r-- | assets/openapi.json | 55 | ||||
-rw-r--r-- | assets/schemas.json | 562 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | patches/body-parser+1.20.1.patch | 11 | ||||
-rw-r--r-- | scripts/test.js | 50 | ||||
-rw-r--r-- | src/api/middlewares/ErrorHandler.ts | 7 |
6 files changed, 561 insertions, 125 deletions
diff --git a/assets/openapi.json b/assets/openapi.json index 4e4d50a8..eff3df07 100644 --- a/assets/openapi.json +++ b/assets/openapi.json @@ -2732,8 +2732,7 @@ }, "required": [ "name", - "type", - "verified" + "type" ] }, "UserRelationsResponse": { @@ -2979,6 +2978,9 @@ }, "show_activity": { "type": "boolean" + }, + "metadata_visibility": { + "type": "boolean" } } } @@ -4951,7 +4953,8 @@ ], "tags": [ "guilds" - ] + ], + "x-permission-required": "MANAGE_ROLES" } }, "/guilds/{guild_id}/roles/{role_id}/": { @@ -7987,6 +7990,52 @@ "connections" ] } + }, + "/channels/{channel_id}/messages/": { + "get": { + "security": [ + { + "bearer": [] + } + ], + "parameters": [ + { + "name": "channel_id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "channel_id" + } + ], + "tags": [ + "channels" + ] + }, + "post": { + "x-right-required": "SEND_MESSAGES", + "x-permission-required": "SEND_MESSAGES", + "security": [ + { + "bearer": [] + } + ], + "parameters": [ + { + "name": "channel_id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "channel_id" + } + ], + "tags": [ + "channels" + ] + } } } } \ No newline at end of file diff --git a/assets/schemas.json b/assets/schemas.json index 8ec8adcc..ee3f7845 100644 --- a/assets/schemas.json +++ b/assets/schemas.json @@ -1126,8 +1126,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -1845,8 +1844,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -2564,8 +2562,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -3278,8 +3275,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -4028,8 +4024,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -4747,8 +4742,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -4762,6 +4756,9 @@ }, "show_activity": { "type": "boolean" + }, + "metadata_visibility": { + "type": "boolean" } }, "additionalProperties": false, @@ -5454,8 +5451,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -6167,8 +6163,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -6889,8 +6884,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -7599,8 +7593,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -8309,8 +8302,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -9038,8 +9030,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -9751,8 +9742,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -10524,8 +10514,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -11256,8 +11245,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -12045,6 +12033,91 @@ } }, "additionalProperties": false + }, + "UserPublic": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "premium_since": { + "type": "string", + "format": "date-time" + }, + "username": { + "type": "string" + }, + "discriminator": { + "type": "string" + }, + "public_flags": { + "type": "integer" + }, + "avatar": { + "type": "string" + }, + "accent_color": { + "type": "integer" + }, + "banner": { + "type": "string" + }, + "bio": { + "type": "string" + }, + "bot": { + "type": "boolean" + }, + "premium_type": { + "type": "integer" + }, + "theme_colors": { + "type": "array", + "items": [ + { + "type": "integer" + }, + { + "type": "integer" + } + ], + "minItems": 2, + "maxItems": 2 + }, + "pronouns": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "bio", + "bot", + "discriminator", + "id", + "premium_since", + "premium_type", + "public_flags", + "username" + ] + }, + "PublicConnectedAccount": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "name": { + "type": "string" + }, + "verified": { + "type": "boolean" + } + }, + "additionalProperties": false, + "required": [ + "name", + "type" + ] } }, "$schema": "http://json-schema.org/draft-07/schema#" @@ -12687,6 +12760,91 @@ } }, "additionalProperties": false + }, + "UserPublic": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "premium_since": { + "type": "string", + "format": "date-time" + }, + "username": { + "type": "string" + }, + "discriminator": { + "type": "string" + }, + "public_flags": { + "type": "integer" + }, + "avatar": { + "type": "string" + }, + "accent_color": { + "type": "integer" + }, + "banner": { + "type": "string" + }, + "bio": { + "type": "string" + }, + "bot": { + "type": "boolean" + }, + "premium_type": { + "type": "integer" + }, + "theme_colors": { + "type": "array", + "items": [ + { + "type": "integer" + }, + { + "type": "integer" + } + ], + "minItems": 2, + "maxItems": 2 + }, + "pronouns": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "bio", + "bot", + "discriminator", + "id", + "premium_since", + "premium_type", + "public_flags", + "username" + ] + }, + "PublicConnectedAccount": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "name": { + "type": "string" + }, + "verified": { + "type": "boolean" + } + }, + "additionalProperties": false, + "required": [ + "name", + "type" + ] } }, "$schema": "http://json-schema.org/draft-07/schema#" @@ -13333,6 +13491,91 @@ } }, "additionalProperties": false + }, + "UserPublic": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "premium_since": { + "type": "string", + "format": "date-time" + }, + "username": { + "type": "string" + }, + "discriminator": { + "type": "string" + }, + "public_flags": { + "type": "integer" + }, + "avatar": { + "type": "string" + }, + "accent_color": { + "type": "integer" + }, + "banner": { + "type": "string" + }, + "bio": { + "type": "string" + }, + "bot": { + "type": "boolean" + }, + "premium_type": { + "type": "integer" + }, + "theme_colors": { + "type": "array", + "items": [ + { + "type": "integer" + }, + { + "type": "integer" + } + ], + "minItems": 2, + "maxItems": 2 + }, + "pronouns": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "bio", + "bot", + "discriminator", + "id", + "premium_since", + "premium_type", + "public_flags", + "username" + ] + }, + "PublicConnectedAccount": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "name": { + "type": "string" + }, + "verified": { + "type": "boolean" + } + }, + "additionalProperties": false, + "required": [ + "name", + "type" + ] } }, "$schema": "http://json-schema.org/draft-07/schema#" @@ -14053,8 +14296,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -14782,8 +15024,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -15501,8 +15742,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -16208,8 +16448,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -17026,8 +17265,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -17841,8 +18079,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -18551,8 +18788,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -19269,8 +19505,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -19980,8 +20215,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -20691,8 +20925,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -21431,8 +21664,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -22142,8 +22374,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -22852,8 +23083,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -23577,8 +23807,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -24291,8 +24520,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -25079,8 +25307,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -25789,8 +26016,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -26499,8 +26725,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -27206,8 +27431,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -27919,8 +28143,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -28642,8 +28865,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -29349,8 +29571,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -30105,8 +30326,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -30847,8 +31067,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -31579,8 +31798,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -32400,8 +32618,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -33106,8 +33323,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -33851,8 +34067,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -34581,8 +34796,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -35366,8 +35580,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -36073,8 +36286,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -36788,8 +37000,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -37493,8 +37704,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -38204,8 +38414,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -38915,8 +39124,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -39626,8 +39834,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -40351,8 +40558,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -41058,8 +41264,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -41794,8 +41999,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -42513,8 +42717,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -42531,6 +42734,37 @@ ], "type": "number" }, + "ConnectedAccountTokenData": { + "type": "object", + "properties": { + "access_token": { + "type": "string" + }, + "token_type": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "refresh_token": { + "type": "string" + }, + "expires_in": { + "type": "integer" + }, + "expires_at": { + "type": "integer" + }, + "fetched_at": { + "type": "integer" + } + }, + "additionalProperties": false, + "required": [ + "access_token", + "fetched_at" + ] + }, "ChannelModifySchema": { "type": "object", "properties": { @@ -43180,8 +43414,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -43210,6 +43443,37 @@ ], "type": "number" }, + "ConnectedAccountTokenData": { + "type": "object", + "properties": { + "access_token": { + "type": "string" + }, + "token_type": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "refresh_token": { + "type": "string" + }, + "expires_in": { + "type": "integer" + }, + "expires_at": { + "type": "integer" + }, + "fetched_at": { + "type": "integer" + } + }, + "additionalProperties": false, + "required": [ + "access_token", + "fetched_at" + ] + }, "ChannelModifySchema": { "type": "object", "properties": { @@ -43859,8 +44123,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -43886,6 +44149,37 @@ ], "type": "number" }, + "ConnectedAccountTokenData": { + "type": "object", + "properties": { + "access_token": { + "type": "string" + }, + "token_type": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "refresh_token": { + "type": "string" + }, + "expires_in": { + "type": "integer" + }, + "expires_at": { + "type": "integer" + }, + "fetched_at": { + "type": "integer" + } + }, + "additionalProperties": false, + "required": [ + "access_token", + "fetched_at" + ] + }, "ChannelModifySchema": { "type": "object", "properties": { @@ -44535,8 +44829,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -44562,6 +44855,37 @@ ], "type": "number" }, + "ConnectedAccountTokenData": { + "type": "object", + "properties": { + "access_token": { + "type": "string" + }, + "token_type": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "refresh_token": { + "type": "string" + }, + "expires_in": { + "type": "integer" + }, + "expires_at": { + "type": "integer" + }, + "fetched_at": { + "type": "integer" + } + }, + "additionalProperties": false, + "required": [ + "access_token", + "fetched_at" + ] + }, "ChannelModifySchema": { "type": "object", "properties": { @@ -45211,8 +45535,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, @@ -45924,8 +46247,7 @@ "additionalProperties": false, "required": [ "name", - "type", - "verified" + "type" ] } }, diff --git a/package.json b/package.json index 16f3c87f..a6017c8a 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "start:cdn": "node dist/cdn/start.js", "start:gateway": "node dist/gateway/start.js", "build": "tsc -p .", + "test": "node scripts/test.js", "lint": "eslint .", "setup": "npm run build && npm run generate:schema", "sync:db": "npm run build && node scripts/syncronise.js", diff --git a/patches/body-parser+1.20.1.patch b/patches/body-parser+1.20.1.patch index 054e24f7..11d1a9d1 100644 --- a/patches/body-parser+1.20.1.patch +++ b/patches/body-parser+1.20.1.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/body-parser/lib/types/json.js b/node_modules/body-parser/lib/types/json.js -index c2745be..7104cfa 100644 +index c2745be..17c2cfe 100644 --- a/node_modules/body-parser/lib/types/json.js +++ b/node_modules/body-parser/lib/types/json.js @@ -18,6 +18,7 @@ var createError = require('http-errors') @@ -28,3 +28,12 @@ index c2745be..7104cfa 100644 } catch (e) { return normalizeJsonSyntaxError(e, { message: e.message.replace('#', char), +@@ -216,7 +217,7 @@ function normalizeJsonSyntaxError (error, obj) { + } + + // replace stack before message for Node.js 0.10 and below +- error.stack = obj.stack.replace(error.message, obj.message) ++ error.stack = obj.stack?.replace(error.message, obj.message) + error.message = obj.message + + return error diff --git a/scripts/test.js b/scripts/test.js new file mode 100644 index 00000000..28ac3778 --- /dev/null +++ b/scripts/test.js @@ -0,0 +1,50 @@ +/* + 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 <https://www.gnu.org/licenses/>. +*/ + +/* + Super simple script to check if the server starts at all, for use in gh actions. + Not a proper test framework by any means. +*/ + +const { spawn } = require("child_process"); +const path = require("path"); + +const server = spawn("node", [ + path.join(__dirname, "..", "dist", "bundle", "start.js"), +]); + +server.stdout.on("data", (data) => { + process.stdout.write(data); + + if (data.toString().toLowerCase().includes("listening")) { + // we good :) + console.log("we good"); + process.exit(); + } +}); + +server.stderr.on("data", (err) => { + process.stdout.write(err); + // we bad :( + process.kill(1); +}); + +server.on("close", (code) => { + console.log("closed with code", code); + process.exit(code); +}); diff --git a/src/api/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts index b8a73298..c417e64f 100644 --- a/src/api/middlewares/ErrorHandler.ts +++ b/src/api/middlewares/ErrorHandler.ts @@ -22,7 +22,7 @@ import { ApiError, FieldError } from "@spacebar/util"; const EntityNotFoundErrorRegex = /"(\w+)"/; export function ErrorHandler( - error: Error, + error: Error & { type?: string }, req: Request, res: Response, next: NextFunction, @@ -50,6 +50,11 @@ export function ErrorHandler( code = Number(error.code); message = error.message; errors = error.errors; + } else if (error?.type == "entity.parse.failed") { + // body-parser failed + httpcode = 400; + code = 50109; + message = "The request body contains invalid JSON."; } else { console.error( `[Error] ${code} ${req.url}\n`, |