From 55fe45e1eb5f966b111cb32befd2ec2661488ba1 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 11 Sep 2021 12:35:04 +0100 Subject: [PATCH] Migrate to rAuth v1. --- OpenAPI.json | 1757 ++++++++++++++++++++++++++++------------ package.json | 2 +- src/index.ts | 12 +- src/openapi/paths.ts | 9 +- src/routes/auth.ts | 278 ++++--- src/routes/bots.ts | 21 +- src/routes/channels.ts | 12 +- src/routes/core.ts | 6 +- src/routes/misc.ts | 18 +- src/routes/servers.ts | 6 +- src/routes/users.ts | 21 +- types/Auth.ts | 28 +- 12 files changed, 1502 insertions(+), 668 deletions(-) diff --git a/OpenAPI.json b/OpenAPI.json index 0170e8e..a3ee5fd 100644 --- a/OpenAPI.json +++ b/OpenAPI.json @@ -1,9 +1,9 @@ { - "__comment": "THIS FILE WAS AUTO-GENERATED USING https://gitlab.insrt.uk/revolt/api. DO NOT EDIT.", + "__comment": "THIS FILE WAS AUTO-GENERATED USING https://github.com/revoltchat/api. DO NOT EDIT.", "openapi": "3.0.0", "info": { "title": "Revolt API", - "version": "0.5.2-alpha.0", + "version": "0.5.3-alpha.0", "description": "User-first privacy focused chat platform built with modern web technologies.\n\n# Authentication\n\nCurrently all relevant requests are authenticated by the use of two headers which identify a session.\n\n", "termsOfService": "https://revolt.chat/terms", "contact": { @@ -26,8 +26,12 @@ "description": "After signing up to Revolt, users must pick a unique username." }, { - "name": "Auth", - "description": "Authenticate with Revolt" + "name": "Account", + "description": "Manage your account." + }, + { + "name": "Session", + "description": "Create and manage sessions." }, { "name": "User Information", @@ -105,7 +109,8 @@ { "name": "Auth", "tags": [ - "Auth" + "Account", + "Session" ] }, { @@ -193,11 +198,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -232,27 +233,49 @@ } }, "responses": { - "200": { + "204": { "description": "Successfully set username" } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } }, - "/auth/create": { + "/account": { + "get": { + "summary": "Fetch Account", + "description": "Fetch account information.", + "tags": [ + "Account" + ], + "responses": { + "200": { + "description": "Account Information", + "content": { + "application/json": { + "schema": { + "$ref": "#/definitions/Account" + } + } + } + } + }, + "security": [ + { + "Session Token": [] + } + ] + } + }, + "/account/create": { "post": { "summary": "Create Account", "description": "Create a new account.", "tags": [ - "Auth" + "Account" ], "requestBody": { "description": "Create Data", @@ -289,35 +312,18 @@ } }, "responses": { - "200": { - "description": "Created account.", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "user_id": { - "description": "User ID", - "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", - "type": "string" - } - }, - "required": [ - "user_id" - ] - } - } - } + "204": { + "description": "Created account." } } } }, - "/auth/resend": { + "/account/reverify": { "post": { "summary": "Resend Verification", "description": "Resend account creation verification email.", "tags": [ - "Auth" + "Account" ], "requestBody": { "description": "Resend Data", @@ -343,96 +349,43 @@ } }, "responses": { - "200": { + "204": { "description": "Resent verification." } } } }, - "/auth/login": { + "/account/verify/:code": { "post": { - "summary": "Login", - "description": "Create a new session.", + "summary": "Verify Email", + "description": "Verifies an email with code.", "tags": [ - "Auth" + "Account" ], - "requestBody": { - "description": "Login Data", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "email": { - "description": "Valid email address", - "type": "string" - }, - "password": { - "description": "Password", - "minLength": 8, - "maxLength": 1024, - "type": "string" - }, - "device_name": { - "description": "Device Name", - "minLength": 0, - "maxLength": 72, - "type": "string" - }, - "captcha": { - "description": "Captcha verification code", - "type": "string" - } - }, - "required": [ - "email", - "password" - ] - } + "parameters": [ + { + "name": "code", + "in": "path", + "required": true, + "description": "Verification Code", + "schema": { + "$ref": "#/definitions/Id" } } - }, + ], "responses": { - "200": { - "description": "Logged in.", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "id": { - "description": "Session ID", - "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", - "type": "string" - }, - "user_id": { - "description": "User ID", - "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", - "type": "string" - }, - "session_token": { - "description": "Session Token", - "type": "string" - } - }, - "required": [ - "id", - "session_token", - "user_id" - ] - } - } - } + "204": { + "description": "Verified email." } } } }, - "/auth/send_reset": { + "/account/reset_password": { "post": { "summary": "Send Password Reset", "description": "Send password reset email.", "tags": [ - "Auth" + "Account" ], "requestBody": { "description": "Reset Data", @@ -458,18 +411,16 @@ } }, "responses": { - "200": { + "204": { "description": "Sent password reset." } } - } - }, - "/auth/reset": { - "post": { + }, + "patch": { "summary": "Password Reset", "description": "Confirm password reset.", "tags": [ - "Auth" + "Account" ], "requestBody": { "description": "Reset Data", @@ -498,71 +449,18 @@ } }, "responses": { - "200": { - "description": "Password was reset." + "204": { + "description": "Password was changed." } } } }, - "/auth/user": { - "get": { - "summary": "Fetch Account", - "description": "Fetch account information.", - "tags": [ - "Auth" - ], - "responses": { - "200": { - "description": "Account Information", - "content": { - "application/json": { - "schema": { - "$ref": "#/definitions/Account" - } - } - } - } - }, - "security": [ - { - "User ID": [], - "Session Token": [] - }, - { - "Bot Token": [] - } - ] - } - }, - "/auth/check": { - "get": { - "summary": "Check Auth", - "description": "Check if we are authenticated.", - "tags": [ - "Auth" - ], - "responses": { - "200": { - "description": "User is authenticated." - } - }, - "security": [ - { - "User ID": [], - "Session Token": [] - }, - { - "Bot Token": [] - } - ] - } - }, - "/auth/change/password": { + "/account/change/password": { "post": { "summary": "Change Password", "description": "Change account password.", "tags": [ - "Auth" + "Account" ], "requestBody": { "description": "Change Data", @@ -577,15 +475,15 @@ "maxLength": 1024, "type": "string" }, - "new_password": { - "description": "Password", + "current_password": { + "description": "Current Password", "minLength": 8, "maxLength": 1024, "type": "string" } }, "required": [ - "new_password", + "current_password", "password" ] } @@ -593,27 +491,23 @@ } }, "responses": { - "200": { + "204": { "description": "Password changed." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } }, - "/auth/change/email": { + "/account/change/email": { "post": { "summary": "Change Email", "description": "Change account email.", "tags": [ - "Auth" + "Account" ], "requestBody": { "description": "Change Data", @@ -622,20 +516,78 @@ "schema": { "type": "object", "properties": { + "current_password": { + "description": "Current Password", + "minLength": 8, + "maxLength": 1024, + "type": "string" + }, + "email": { + "description": "Valid email", + "type": "string" + } + }, + "required": [ + "current_password", + "email" + ] + } + } + } + }, + "responses": { + "204": { + "description": "Email changed." + } + }, + "security": [ + { + "Session Token": [] + } + ] + } + }, + "/session/login": { + "post": { + "summary": "Login", + "description": "Login to an account.", + "tags": [ + "Session" + ], + "requestBody": { + "description": "Login Data", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "email": { + "description": "Valid email address", + "type": "string" + }, "password": { "description": "Password", "minLength": 8, "maxLength": 1024, "type": "string" }, - "new_email": { - "description": "Valid email", + "challenge": { + "description": "Security Key Challenge", + "type": "string" + }, + "friendly_name": { + "description": "Session Friendly Name", + "minLength": 0, + "maxLength": 72, + "type": "string" + }, + "captcha": { + "description": "Captcha verification code", "type": "string" } }, "required": [ - "new_email", - "password" + "email" ] } } @@ -643,26 +595,24 @@ }, "responses": { "200": { - "description": "Email changed." + "description": "Logged in.", + "content": { + "application/json": { + "schema": { + "$ref": "#/definitions/Session" + } + } + } } - }, - "security": [ - { - "User ID": [], - "Session Token": [] - }, - { - "Bot Token": [] - } - ] + } } }, - "/auth/sessions/:session": { + "/session/logout": { "delete": { - "summary": "Delete Session", - "description": "Delete existing session.", + "summary": "Logout", + "description": "Close current session.", "tags": [ - "Auth" + "Session" ], "parameters": [ { @@ -676,27 +626,102 @@ } ], "responses": { - "200": { + "204": { + "description": "Logged out." + } + }, + "security": [ + { + "Session Token": [] + } + ] + } + }, + "/session/:session": { + "patch": { + "summary": "Edit Session", + "description": "Edit session information.", + "tags": [ + "Session" + ], + "parameters": [ + { + "name": "session", + "in": "path", + "required": true, + "description": "Session ID", + "schema": { + "$ref": "#/definitions/Id" + } + } + ], + "requestBody": { + "description": "Edit Data", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "friendly_name": { + "description": "Session Friendly Name", + "minLength": 0, + "maxLength": 72, + "type": "string" + } + }, + "required": [ + "friendly_name" + ] + } + } + } + }, + "responses": { + "204": { + "description": "Edited session." + } + }, + "security": [ + { + "Session Token": [] + } + ] + }, + "delete": { + "summary": "Delete Session", + "description": "Delete a specific session.", + "tags": [ + "Session" + ], + "parameters": [ + { + "name": "session", + "in": "path", + "required": true, + "description": "Session ID", + "schema": { + "$ref": "#/definitions/Id" + } + } + ], + "responses": { + "204": { "description": "Deleted session." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } }, - "/auth/sessions": { + "/session/all": { "get": { "summary": "Fetch Sessions", "description": "Fetch all sessions.", "tags": [ - "Auth" + "Session" ], "responses": { "200": { @@ -706,22 +731,26 @@ "schema": { "type": "array", "items": { - "type": "object", - "properties": { - "id": { - "description": "Session ID", - "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", - "type": "string" + "$ref": "#/definitions/SessionInfo" + }, + "definitions": { + "SessionInfo": { + "type": "object", + "properties": { + "_id": { + "description": "Session ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "name": { + "description": "Device name", + "type": "string" + } }, - "friendly_name": { - "description": "Session device name", - "type": "string" - } - }, - "required": [ - "friendly_name", - "id" - ] + "required": [ + "name" + ] + } } } } @@ -730,34 +759,34 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] - } - }, - "/auth/logout": { - "get": { - "summary": "Logout", - "description": "Delete current session.", + }, + "delete": { + "summary": "Delete All Sessions", + "description": "Delete all active sesssions.", "tags": [ - "Auth" + "Session" + ], + "parameters": [ + { + "name": "revoke_self", + "in": "query", + "description": "Whether to revoke current session too.", + "schema": { + "type": "boolean" + } + } ], "responses": { - "200": { - "description": "Logged out." + "204": { + "description": "Deleted session." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -794,7 +823,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -883,13 +911,12 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed user object." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -935,17 +962,13 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed user object." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -982,7 +1005,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1068,7 +1090,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1150,7 +1171,6 @@ "_id", "active", "channel_type", - "last_message", "recipients" ] }, @@ -1343,12 +1363,15 @@ "permissions": { "description": "Permissions given to group members", "type": "number" + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", "channel_type", - "last_message", "name", "owner", "recipients" @@ -1376,7 +1399,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1417,7 +1439,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1490,11 +1511,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -1531,11 +1548,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -1572,11 +1585,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -1611,11 +1620,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -1652,11 +1657,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -1691,11 +1692,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -1732,7 +1729,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1782,6 +1778,10 @@ "maxLength": 128, "type": "string" }, + "nsfw": { + "description": "Whether this channel is not safe for work", + "type": "boolean" + }, "remove": { "description": "Field to remove from channel object", "enum": [ @@ -1796,13 +1796,12 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed channel object." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1828,13 +1827,12 @@ } ], "responses": { - "200": { + "204": { "description": "Deleted Channel" } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1884,7 +1882,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1939,13 +1936,12 @@ } }, "responses": { - "200": { + "204": { "description": "Successfully updated permissions." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -1991,13 +1987,12 @@ } }, "responses": { - "200": { + "204": { "description": "Successfully updated permissions." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -2052,22 +2047,25 @@ }, "replies": { "description": "Messages to reply to.", - "type": "object", - "properties": { - "id": { - "description": "Message Id", - "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", - "type": "string" + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "description": "Message Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "mention": { + "description": "Whether this reply should mention the message's author.", + "type": "boolean" + } }, - "mention": { - "description": "Whether this reply should mention the message's author.", - "type": "boolean" - } - }, - "required": [ - "id", - "mention" - ] + "required": [ + "id", + "mention" + ] + } } }, "required": [ @@ -2092,7 +2090,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -2621,6 +2618,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -2779,7 +2779,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -3311,6 +3311,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -3469,7 +3472,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -3997,7 +4000,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -4047,7 +4049,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -4103,13 +4104,12 @@ } }, "responses": { - "200": { + "204": { "description": "Message was changed." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -4144,13 +4144,12 @@ } ], "responses": { - "200": { + "204": { "description": "Message was deleted." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -4658,6 +4657,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -4816,7 +4818,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -4928,7 +4930,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -5461,6 +5462,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -5619,7 +5623,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -6151,6 +6155,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -6309,7 +6316,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -6837,7 +6844,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -6874,17 +6880,13 @@ } ], "responses": { - "200": { + "204": { "description": "Acknowledged message." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -6928,6 +6930,10 @@ "items": { "type": "string" } + }, + "nsfw": { + "description": "Whether this group is not safe for work", + "type": "boolean" } }, "required": [ @@ -6952,11 +6958,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -7269,7 +7271,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7304,17 +7305,13 @@ } ], "responses": { - "200": { + "204": { "description": "User was added to the group." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -7345,17 +7342,13 @@ } ], "responses": { - "200": { + "204": { "description": "User was removed from the group." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -7401,7 +7394,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7442,7 +7434,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7552,6 +7543,10 @@ } } }, + "nsfw": { + "description": "Whether this server is not safe for work", + "type": "boolean" + }, "remove": { "description": "Field to remove from channel object", "enum": [ @@ -7567,13 +7562,12 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed channel object." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7599,13 +7593,12 @@ } ], "responses": { - "200": { + "204": { "description": "Deleted Server" } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7629,17 +7622,21 @@ "type": "object", "properties": { "name": { - "description": "Group name", + "description": "Server name", "minLength": 1, "maxLength": 32, "type": "string" }, "description": { - "description": "Group description", + "description": "Server description", "minLength": 0, "maxLength": 1024, "type": "string" }, + "nsfw": { + "description": "Whether this server is not safe for work", + "type": "boolean" + }, "nonce": { "description": "Nonce value, prefer to use ULIDs here for better feature support.\n\nUsed to prevent double requests to create objects.", "minLength": 1, @@ -7669,11 +7666,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -7723,6 +7716,10 @@ "maxLength": 1024, "type": "string" }, + "nsfw": { + "description": "Whether this channel is not safe for work", + "type": "boolean" + }, "nonce": { "description": "Nonce value, prefer to use ULIDs here for better feature support.\n\nUsed to prevent double requests to create objects.", "minLength": 1, @@ -7741,7 +7738,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7770,7 +7766,6 @@ ], "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7798,17 +7793,13 @@ } ], "responses": { - "200": { + "204": { "description": "Marked as read." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -7854,7 +7845,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7919,13 +7909,12 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed member object." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -7940,13 +7929,12 @@ "Server Members" ], "responses": { - "200": { + "204": { "description": "Removed Member" } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -8473,13 +8461,12 @@ } }, "responses": { - "200": { + "204": { "description": "Banned user." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -8514,13 +8501,12 @@ } ], "responses": { - "200": { + "204": { "description": "Unbanned user." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -8764,7 +8750,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -8782,10 +8767,10 @@ ], "parameters": [ { - "name": "channel", + "name": "server", "in": "path", "required": true, - "description": "Channel ID", + "description": "Server ID", "schema": { "$ref": "#/definitions/Id" } @@ -8834,13 +8819,12 @@ } }, "responses": { - "200": { + "204": { "description": "Successfully updated permissions." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -8901,13 +8885,12 @@ } }, "responses": { - "200": { + "204": { "description": "Successfully updated permissions." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -8994,7 +8977,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -9012,10 +8994,10 @@ ], "parameters": [ { - "name": "channel", + "name": "server", "in": "path", "required": true, - "description": "Channel ID", + "description": "Server ID", "schema": { "$ref": "#/definitions/Id" } @@ -9087,13 +9069,12 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed role object." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -9109,10 +9090,10 @@ ], "parameters": [ { - "name": "channel", + "name": "server", "in": "path", "required": true, - "description": "Channel ID", + "description": "Server ID", "schema": { "$ref": "#/definitions/Id" } @@ -9128,13 +9109,12 @@ } ], "responses": { - "200": { + "204": { "description": "Successfully deleted role." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -9158,9 +9138,10 @@ "type": "object", "properties": { "name": { - "description": "Bot name", - "minLength": 1, + "description": "Bot username", + "minLength": 2, "maxLength": 32, + "pattern": "^[a-zA-Z0-9_.]+$", "type": "string" } }, @@ -9185,11 +9166,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -9207,10 +9184,25 @@ "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Bot" + "type": "object", + "properties": { + "bots": { + "type": "array", + "items": { + "$ref": "#/definitions/Bot" + } + }, + "users": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } }, + "required": [ + "bots", + "users" + ], "definitions": { "Bot": { "type": "object", @@ -9233,18 +9225,279 @@ "description": "Whether the bot can be added by anyone", "type": "boolean" }, - "interactionsURL": { + "interactions_url": { "description": "Interactions endpoint URL\n\nRequired for dynamic interactions such as bot commands and message actions. Events will be sent over HTTP and a response may be generated directly.", "type": "string" } }, "required": [ "_id", - "interactionsURL", "owner", "public", "token" ] + }, + "User": { + "type": "object", + "properties": { + "_id": { + "description": "User ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "username": { + "description": "Username", + "minLength": 2, + "maxLength": 32, + "pattern": "^[a-zA-Z0-9_.]+$", + "type": "string" + }, + "avatar": { + "description": "User avatar", + "type": "object", + "properties": { + "_id": { + "description": "Attachment ID", + "minLength": 1, + "maxLength": 128, + "type": "string" + }, + "tag": { + "$ref": "#/definitions/AttachmentTag" + }, + "size": { + "description": "File size (in bytes)", + "type": "number" + }, + "filename": { + "description": "File name", + "type": "string" + }, + "metadata": { + "description": "Metadata", + "anyOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "File" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Text" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Audio" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Image" + ] + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + } + }, + "required": [ + "height", + "type", + "width" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Video" + ] + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + } + }, + "required": [ + "height", + "type", + "width" + ] + } + ] + }, + "content_type": { + "description": "Content type", + "type": "string" + } + }, + "required": [ + "_id", + "content_type", + "filename", + "metadata", + "size", + "tag" + ] + }, + "relations": { + "description": "Relationships with other known users\nOnly present if fetching self", + "type": "array", + "items": { + "allOf": [ + { + "type": "object", + "properties": { + "status": { + "$ref": "#/definitions/RelationshipStatus" + } + }, + "required": [ + "status" + ] + }, + { + "type": "object", + "properties": { + "_id": { + "description": "Other user's ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "_id" + ] + } + ] + } + }, + "badges": { + "description": "Bitfield of user's badges", + "type": "number" + }, + "status": { + "description": "User status", + "type": "object", + "properties": { + "text": { + "description": "Custom status text", + "minLength": 1, + "maxLength": 128, + "type": "string" + }, + "presence": { + "$ref": "#/definitions/Presence" + } + } + }, + "relationship": { + "$ref": "#/definitions/RelationshipStatus", + "description": "Relationship to user" + }, + "online": { + "description": "Whether the user is online", + "type": "boolean" + }, + "flags": { + "description": "User flags\n\n`0x1`: Account is suspended\n`0x2`: Account was deleted\n`0x4`: Account is banned", + "type": "number" + }, + "bot": { + "$ref": "#/definitions/BotInformation", + "description": "Bot information, present if user is a bot." + } + }, + "required": [ + "_id", + "username" + ] + }, + "AttachmentTag": { + "description": "Attachment tag", + "enum": [ + "attachments", + "avatars", + "backgrounds", + "banners", + "icons" + ], + "type": "string" + }, + "RelationshipStatus": { + "description": "Your relationship with the user", + "enum": [ + "Blocked", + "BlockedOther", + "Friend", + "Incoming", + "None", + "Outgoing", + "User" + ], + "type": "string" + }, + "Presence": { + "description": "User presence", + "enum": [ + "Busy", + "Idle", + "Invisible", + "Online" + ], + "type": "string" + }, + "BotInformation": { + "description": "Bot information", + "type": "object", + "properties": { + "owner": { + "description": "The User ID of the owner of this bot", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "owner" + ] } } } @@ -9254,11 +9507,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -9287,7 +9536,316 @@ "content": { "application/json": { "schema": { - "$ref": "#/definitions/Bot" + "type": "object", + "properties": { + "bot": { + "$ref": "#/definitions/Bot" + }, + "user": { + "$ref": "#/definitions/User" + } + }, + "required": [ + "bot", + "user" + ], + "definitions": { + "Bot": { + "type": "object", + "properties": { + "_id": { + "description": "Bot ID\n\nThis matches the bot's User ID.", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "owner": { + "description": "Bot owner's User ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "token": { + "description": "Bot authentication token", + "type": "string" + }, + "public": { + "description": "Whether the bot can be added by anyone", + "type": "boolean" + }, + "interactions_url": { + "description": "Interactions endpoint URL\n\nRequired for dynamic interactions such as bot commands and message actions. Events will be sent over HTTP and a response may be generated directly.", + "type": "string" + } + }, + "required": [ + "_id", + "owner", + "public", + "token" + ] + }, + "User": { + "type": "object", + "properties": { + "_id": { + "description": "User ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "username": { + "description": "Username", + "minLength": 2, + "maxLength": 32, + "pattern": "^[a-zA-Z0-9_.]+$", + "type": "string" + }, + "avatar": { + "description": "User avatar", + "type": "object", + "properties": { + "_id": { + "description": "Attachment ID", + "minLength": 1, + "maxLength": 128, + "type": "string" + }, + "tag": { + "$ref": "#/definitions/AttachmentTag" + }, + "size": { + "description": "File size (in bytes)", + "type": "number" + }, + "filename": { + "description": "File name", + "type": "string" + }, + "metadata": { + "description": "Metadata", + "anyOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "File" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Text" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Audio" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Image" + ] + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + } + }, + "required": [ + "height", + "type", + "width" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Video" + ] + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + } + }, + "required": [ + "height", + "type", + "width" + ] + } + ] + }, + "content_type": { + "description": "Content type", + "type": "string" + } + }, + "required": [ + "_id", + "content_type", + "filename", + "metadata", + "size", + "tag" + ] + }, + "relations": { + "description": "Relationships with other known users\nOnly present if fetching self", + "type": "array", + "items": { + "allOf": [ + { + "type": "object", + "properties": { + "status": { + "$ref": "#/definitions/RelationshipStatus" + } + }, + "required": [ + "status" + ] + }, + { + "type": "object", + "properties": { + "_id": { + "description": "Other user's ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "_id" + ] + } + ] + } + }, + "badges": { + "description": "Bitfield of user's badges", + "type": "number" + }, + "status": { + "description": "User status", + "type": "object", + "properties": { + "text": { + "description": "Custom status text", + "minLength": 1, + "maxLength": 128, + "type": "string" + }, + "presence": { + "$ref": "#/definitions/Presence" + } + } + }, + "relationship": { + "$ref": "#/definitions/RelationshipStatus", + "description": "Relationship to user" + }, + "online": { + "description": "Whether the user is online", + "type": "boolean" + }, + "flags": { + "description": "User flags\n\n`0x1`: Account is suspended\n`0x2`: Account was deleted\n`0x4`: Account is banned", + "type": "number" + }, + "bot": { + "$ref": "#/definitions/BotInformation", + "description": "Bot information, present if user is a bot." + } + }, + "required": [ + "_id", + "username" + ] + }, + "AttachmentTag": { + "description": "Attachment tag", + "enum": [ + "attachments", + "avatars", + "backgrounds", + "banners", + "icons" + ], + "type": "string" + }, + "RelationshipStatus": { + "description": "Your relationship with the user", + "enum": [ + "Blocked", + "BlockedOther", + "Friend", + "Incoming", + "None", + "Outgoing", + "User" + ], + "type": "string" + }, + "Presence": { + "description": "User presence", + "enum": [ + "Busy", + "Idle", + "Invisible", + "Online" + ], + "type": "string" + }, + "BotInformation": { + "description": "Bot information", + "type": "object", + "properties": { + "owner": { + "description": "The User ID of the owner of this bot", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "owner" + ] + } + } } } } @@ -9295,11 +9853,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -9317,16 +9871,17 @@ "type": "object", "properties": { "name": { - "description": "Channel name", - "minLength": 1, + "description": "Bot username", + "minLength": 2, "maxLength": 32, + "pattern": "^[a-zA-Z0-9_.]+$", "type": "string" }, "public": { "description": "Whether the bot can be added by anyone", "type": "boolean" }, - "interactionsURL": { + "interactions_url": { "description": "Interactions URL", "minLength": 1, "maxLength": 2048, @@ -9345,17 +9900,13 @@ } }, "responses": { - "200": { + "204": { "description": "Succesfully changed bot object." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -9377,17 +9928,13 @@ } ], "responses": { - "200": { + "204": { "description": "Deleted bot." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -9424,11 +9971,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -9487,17 +10030,13 @@ } }, "responses": { - "200": { + "204": { "description": "Added bot to server / group." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -9534,7 +10073,6 @@ }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -9672,7 +10210,6 @@ "_id", "active", "channel_type", - "last_message", "recipients" ] }, @@ -9877,12 +10414,15 @@ "permissions": { "description": "Permissions given to group members", "type": "number" + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", "channel_type", - "last_message", "name", "owner", "recipients" @@ -10056,11 +10596,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ] @@ -10079,8 +10622,7 @@ } }, "required": [ - "channel_type", - "last_message" + "channel_type" ] }, { @@ -10251,11 +10793,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ] @@ -10422,7 +10967,7 @@ } }, "default_permissions": { - "description": "Default permissions for all members", + "description": "Default permissions for all members\n\nThis is a tuple consisting of server and channel permissions in that order.", "type": "array", "items": [ { @@ -10686,6 +11231,10 @@ "size", "tag" ] + }, + "nsfw": { + "description": "Whether this server is marked as not safe for work", + "type": "boolean" } }, "required": [ @@ -10722,11 +11271,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] }, @@ -10748,13 +11293,12 @@ } ], "responses": { - "200": { + "204": { "description": "Deleted invite." } }, "security": [ { - "User ID": [], "Session Token": [] }, { @@ -10819,11 +11363,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -10859,17 +11399,13 @@ } }, "responses": { - "200": { + "204": { "description": "Successfully synced data." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -10883,11 +11419,53 @@ ], "responses": { "200": { - "description": "Unreads Data", + "description": "Array of Unreads Data", "content": { "application/json": { "schema": { - "$ref": "#/definitions/ChannelUnread" + "type": "array", + "items": { + "$ref": "#/definitions/ChannelUnread" + }, + "definitions": { + "ChannelUnread": { + "type": "object", + "properties": { + "_id": { + "type": "object", + "properties": { + "channel": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "user": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "channel", + "user" + ] + }, + "last_id": { + "type": "string" + }, + "mentions": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "_id", + "last_id" + ] + } + } } } } @@ -10895,11 +11473,7 @@ }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -10922,17 +11496,13 @@ } }, "responses": { - "200": { + "204": { "description": "Subscribed successfully." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -10945,17 +11515,13 @@ "Web Push" ], "responses": { - "200": { + "204": { "description": "Unsubscribed successfully." } }, "security": [ { - "User ID": [], "Session Token": [] - }, - { - "Bot Token": [] } ] } @@ -10965,7 +11531,7 @@ "Account": { "type": "object", "properties": { - "id": { + "_id": { "description": "User ID", "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", "type": "string" @@ -10976,14 +11542,14 @@ } }, "required": [ - "email", - "id" + "_id", + "email" ] }, "Session": { "type": "object", "properties": { - "id": { + "_id": { "description": "Session ID", "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", "type": "string" @@ -10993,16 +11559,42 @@ "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", "type": "string" }, - "session_token": { + "token": { "maxLength": 64, "type": "string" + }, + "name": { + "description": "Device name", + "type": "string" + }, + "subscription": { + "description": "Web Push subscription", + "type": "string" } }, "required": [ - "session_token", + "name", + "token", "user_id" ] }, + "SessionInfo": { + "type": "object", + "properties": { + "_id": { + "description": "Session ID", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "name": { + "description": "Device name", + "type": "string" + } + }, + "required": [ + "name" + ] + }, "AttachmentId": { "description": "Attachment ID", "minLength": 1, @@ -11304,14 +11896,13 @@ "description": "Whether the bot can be added by anyone", "type": "boolean" }, - "interactionsURL": { + "interactions_url": { "description": "Interactions endpoint URL\n\nRequired for dynamic interactions such as bot commands and message actions. Events will be sent over HTTP and a response may be generated directly.", "type": "string" } }, "required": [ "_id", - "interactionsURL", "owner", "public", "token" @@ -11629,7 +12220,6 @@ "_id", "active", "channel_type", - "last_message", "recipients" ], "definitions": { @@ -11835,12 +12425,15 @@ "permissions": { "description": "Permissions given to group members", "type": "number" + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", "channel_type", - "last_message", "name", "owner", "recipients" @@ -12015,11 +12608,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ], @@ -12195,11 +12791,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ] @@ -12218,8 +12817,7 @@ } }, "required": [ - "channel_type", - "last_message" + "channel_type" ] } ], @@ -12395,11 +12993,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ] @@ -12532,7 +13133,6 @@ "_id", "active", "channel_type", - "last_message", "recipients" ] }, @@ -12737,12 +13337,15 @@ "permissions": { "description": "Permissions given to group members", "type": "number" + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", "channel_type", - "last_message", "name", "owner", "recipients" @@ -12916,11 +13519,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ] @@ -12939,8 +13545,7 @@ } }, "required": [ - "channel_type", - "last_message" + "channel_type" ] }, { @@ -13111,11 +13716,14 @@ "additionalProperties": { "type": "number" } + }, + "nsfw": { + "description": "Whether this channel is marked as not safe for work", + "type": "boolean" } }, "required": [ "_id", - "description", "name", "server" ] @@ -13606,6 +14214,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -13764,7 +14375,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -14893,6 +15504,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -15061,6 +15675,9 @@ }, "id": { "type": "string" + }, + "timestamp": { + "type": "string" } }, "required": [ @@ -15219,7 +15836,7 @@ "icon_url": { "type": "string" }, - "color": { + "colour": { "type": "string" } }, @@ -15891,7 +16508,7 @@ } }, "default_permissions": { - "description": "Default permissions for all members", + "description": "Default permissions for all members\n\nThis is a tuple consisting of server and channel permissions in that order.", "type": "array", "items": [ { @@ -16155,6 +16772,10 @@ "size", "tag" ] + }, + "nsfw": { + "description": "Whether this server is marked as not safe for work", + "type": "boolean" } }, "required": [ @@ -17111,10 +17732,10 @@ } } }, - "SetSettingsData": { - "type": "object", - "additionalProperties": { - "type": "string" + "FetchUnreads": { + "type": "array", + "items": { + "$ref": "#/definitions/ChannelUnread" }, "definitions": { "AttachmentTag": { @@ -17164,6 +17785,43 @@ "required": [ "owner" ] + }, + "ChannelUnread": { + "type": "object", + "properties": { + "_id": { + "type": "object", + "properties": { + "channel": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "user": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "channel", + "user" + ] + }, + "last_id": { + "type": "string" + }, + "mentions": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "_id", + "last_id" + ] } } }, @@ -17219,6 +17877,43 @@ "required": [ "owner" ] + }, + "ChannelUnread": { + "type": "object", + "properties": { + "_id": { + "type": "object", + "properties": { + "channel": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "user": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "channel", + "user" + ] + }, + "last_id": { + "type": "string" + }, + "mentions": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "_id", + "last_id" + ] } } }, @@ -17275,6 +17970,43 @@ "required": [ "owner" ] + }, + "ChannelUnread": { + "type": "object", + "properties": { + "_id": { + "type": "object", + "properties": { + "channel": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "user": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "channel", + "user" + ] + }, + "last_id": { + "type": "string" + }, + "mentions": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "_id", + "last_id" + ] } } }, @@ -17331,6 +18063,43 @@ "required": [ "owner" ] + }, + "ChannelUnread": { + "type": "object", + "properties": { + "_id": { + "type": "object", + "properties": { + "channel": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + }, + "user": { + "description": "Id", + "pattern": "[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}", + "type": "string" + } + }, + "required": [ + "channel", + "user" + ] + }, + "last_id": { + "type": "string" + }, + "mentions": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "_id", + "last_id" + ] } } } @@ -17343,23 +18112,17 @@ ], "components": { "securitySchemes": { - "User ID": { - "type": "apiKey", - "in": "header", - "name": "x-user-id", - "description": "User ID is found when calling `/auth/login`.\n" - }, "Session Token": { "type": "apiKey", "in": "header", "name": "x-session-token", - "description": "Session is created by calling `/auth/login`.\n" + "description": "Session is created by calling `/session/login`.\n" }, "Bot Token": { "type": "apiKey", "in": "header", "name": "x-bot-token", - "description": "Bot tokens can be found by fetching `/bots/:id`.\n" + "description": "Generate a bot token in-app by going to [\"My Bots\"](https://app.revolt.chat/settings/bots) in user settings.\n" } } } diff --git a/package.json b/package.json index 90fe3a2..a105323 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "revolt-api", - "version": "0.5.2-alpha.2", + "version": "0.5.3-alpha.0", "description": "Revolt API typings", "main": "dist/index.js", "type": "module", diff --git a/src/index.ts b/src/index.ts index be03cfa..d3fe5af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,7 @@ import './routes/index.js'; async function generate(): Promise { return { - ['__comment' as any]: "THIS FILE WAS AUTO-GENERATED USING https://gitlab.insrt.uk/revolt/api. DO NOT EDIT.", + ['__comment' as any]: "THIS FILE WAS AUTO-GENERATED USING https://github.com/revoltchat/api. DO NOT EDIT.", openapi: "3.0.0", info: await info(), tags, @@ -28,23 +28,17 @@ async function generate(): Promise { ], components: { securitySchemes: { - 'User ID': { - type: "apiKey", - in: "header", - name: "x-user-id", - description: "User ID is found when calling `/auth/login`.\n" - }, 'Session Token': { type: "apiKey", in: "header", name: "x-session-token", - description: "Session is created by calling `/auth/login`.\n" + description: "Session is created by calling `/session/login`.\n" }, 'Bot Token': { type: "apiKey", in: "header", name: "x-bot-token", - description: "Bot tokens can be found by fetching `/bots/:id`.\n" + description: "Generate a bot token in-app by going to [\"My Bots\"](https://app.revolt.chat/settings/bots) in user settings.\n" } } } diff --git a/src/openapi/paths.ts b/src/openapi/paths.ts index f439b39..bef3747 100644 --- a/src/openapi/paths.ts +++ b/src/openapi/paths.ts @@ -50,12 +50,15 @@ export function route(summary: string, description: string, obj: Omit): OpenAPIV3.OperationObject { +export function routeAuthenticated(summary: string, description: string, obj: Omit, disallowBots?: boolean): OpenAPIV3.OperationObject { return { ...route(summary, description, obj), - security: [ + security: disallowBots ? [ + { + 'Session Token': [] + } + ] : [ { - 'User ID': [], 'Session Token': [] }, { diff --git a/src/routes/auth.ts b/src/routes/auth.ts index a420d26..e25804e 100644 --- a/src/routes/auth.ts +++ b/src/routes/auth.ts @@ -1,13 +1,22 @@ -import { body, parameter, ref, success } from "../openapi/generators.js"; +import { body, noContent, parameter, ref, success } from "../openapi/generators.js"; import { group, resource, route, routeAuthenticated, tag } from "../openapi/paths.js"; import { schema } from "../typescript.js"; group("Auth"); -//#region Auth -tag("Auth", "Authenticate with Revolt"); +//#region Account +tag("Account", "Manage your account."); -resource('/auth/create', { +resource('/account', { + get: routeAuthenticated( + "Fetch Account", + "Fetch account information.", + await success("Account Information", ref("Account")), + true + ) +}); + +resource('/account/create', { post: route( "Create Account", "Create a new account.", @@ -37,21 +46,12 @@ resource('/auth/create', { captcha?: string; } `), - ...await success("Created account.", schema` - import { Id } from './_common'; - - interface ${'CreateResponse'} { - /** - * User ID - */ - user_id: Id; - } - `) + ...await noContent("Created account.") } ) }); -resource('/auth/resend', { +resource('/account/reverify', { post: route( "Resend Verification", "Resend account creation verification email.", @@ -69,68 +69,25 @@ resource('/auth/resend', { captcha?: string; } `), - ...await success("Resent verification.") + ...await noContent("Resent verification.") } ) }); -resource('/auth/login', { +resource('/account/verify/:code', { post: route( - "Login", - "Create a new session.", + "Verify Email", + "Verifies an email with code.", { - ...await body("Login Data", schema` - interface ${'LoginData'} { - /** - * Valid email address - */ - email: string; - - /** - * Password - * @minLength 8 - * @maxLength 1024 - */ - password: string; - - /** - * Device Name - * @minLength 0 - * @maxLength 72 - */ - device_name?: string; - - /** - * Captcha verification code - */ - captcha?: string; - } - `), - ...await success("Logged in.", schema` - import { Id } from './_common'; - - interface ${'LoginResponse'} { - /** - * Session ID - */ - id: Id; - - /** - * User ID - */ - user_id: Id; - - /** - * Session Token - */ - session_token: string; - } - `) + parameters: [ + await parameter("code", "Verification Code", ref("Id")) + ], + ...await noContent("Verified email.") } ) }); -resource('/auth/send_reset', { +resource('/account/reset_password', { post: route( "Send Password Reset", "Send password reset email.", @@ -148,13 +105,10 @@ resource('/auth/send_reset', { captcha?: string; } `), - ...await success("Sent password reset.") + ...await noContent("Sent password reset.") } - ) -}); - -resource('/auth/reset', { - post: route( + ), + patch: route( "Password Reset", "Confirm password reset.", { @@ -173,28 +127,12 @@ resource('/auth/reset', { token: string; } `), - ...await success("Password was reset.") + ...await noContent("Password was changed.") } ) }); -resource('/auth/user', { - get: routeAuthenticated( - "Fetch Account", - "Fetch account information.", - await success("Account Information", ref("Account")) - ) -}); - -resource('/auth/check', { - get: routeAuthenticated( - "Check Auth", - "Check if we are authenticated.", - await success("User is authenticated.") - ) -}); - -resource('/auth/change/password', { +resource('/account/change/password', { post: routeAuthenticated( "Change Password", "Change account password.", @@ -209,19 +147,20 @@ resource('/auth/change/password', { password: string; /** - * Password + * Current Password * @minLength 8 * @maxLength 1024 */ - new_password: string; + current_password: string; } `), - ...await success("Password changed.") - } + ...await noContent("Password changed.") + }, + true ) }); -resource('/auth/change/email', { +resource('/account/change/email', { post: routeAuthenticated( "Change Email", "Change account email.", @@ -229,63 +168,148 @@ resource('/auth/change/email', { ...await body("Change Data", schema` interface ${'ChangeData'} { /** - * Password + * Current Password * @minLength 8 * @maxLength 1024 */ - password: string; + current_password: string; /** * Valid email */ - new_email: string; + email: string; } `), - ...await success("Email changed.") + ...await noContent("Email changed.") + }, + true + ) +}); +//#endregion + +//#region Session +tag("Session", "Create and manage sessions."); + +resource('/session/login', { + post: route( + "Login", + "Login to an account.", + { + ...await body("Login Data", schema` + interface ${'LoginData'} { + /** + * Valid email address + */ + email: string; + + /** + * Password + * @minLength 8 + * @maxLength 1024 + */ + password?: string; + + /** + * Security Key Challenge + */ + challenge?: string; + + /** + * Session Friendly Name + * @minLength 0 + * @maxLength 72 + */ + friendly_name?: string; + + /** + * Captcha verification code + */ + captcha?: string; + } + `), + ...await success("Logged in.", ref("Session")) } ) }); -resource('/auth/sessions/:session', { +resource('/session/logout', { delete: routeAuthenticated( - "Delete Session", - "Delete existing session.", + "Logout", + "Close current session.", { parameters: [ await parameter("session", "Session ID", ref("Id")) ], - ...await success("Deleted session.") - } + ...await noContent("Logged out.") + }, + true ) }); -resource('/auth/sessions', { +resource('/session/:session', { + patch: routeAuthenticated( + "Edit Session", + "Edit session information.", + { + parameters: [ + await parameter("session", "Session ID", ref("Id")) + ], + ...await body("Edit Data", schema` + interface ${'SessionEditData'} { + /** + * Session Friendly Name + * @minLength 0 + * @maxLength 72 + */ + friendly_name: string; + } + `), + ...await noContent("Edited session.") + }, + true + ), + delete: routeAuthenticated( + "Delete Session", + "Delete a specific session.", + { + parameters: [ + await parameter("session", "Session ID", ref("Id")) + ], + ...await noContent("Deleted session.") + }, + true + ) +}); + +resource('/session/all', { get: routeAuthenticated( "Fetch Sessions", "Fetch all sessions.", await success("Sessions", schema` - import { Id } from './_common'; + import type { Id } from './_common'; + import type { SessionInfo } from './Auth'; - type ${'Sessions'} = { - /** - * Session ID - */ - id: Id - - /** - * Session device name - */ - friendly_name: string - }[]; - `) - ) -}); - -resource('/auth/logout', { - get: routeAuthenticated( - "Logout", - "Delete current session.", - await success("Logged out.") + type ${'Sessions'} = SessionInfo[]; + `), + true + ), + delete: routeAuthenticated( + "Delete All Sessions", + "Delete all active sesssions.", + { + parameters: [ + { + name: 'revoke_self', + in: 'query', + description: "Whether to revoke current session too.", + schema: { + type: 'boolean' + } + } + ], + ...await noContent("Deleted session.") + }, + true ) }); //#endregion \ No newline at end of file diff --git a/src/routes/bots.ts b/src/routes/bots.ts index 40d8a2d..fbce115 100644 --- a/src/routes/bots.ts +++ b/src/routes/bots.ts @@ -26,7 +26,8 @@ resource('/bots/create', { "Succesfully created a new bot.", ref("Bot") ) - } + }, + true ) }); @@ -43,7 +44,8 @@ resource('/bots/@me', { users: User[] }; `) - } + }, + true ) }); @@ -67,7 +69,8 @@ resource('/bots/:bot', { user: User }; `) - } + }, + true ), patch: routeAuthenticated( "Edit Bot", @@ -101,7 +104,8 @@ resource('/bots/:bot', { } `), ...await noContent("Succesfully changed bot object.") - } + }, + true ), delete: routeAuthenticated( "Delete Bot", @@ -109,7 +113,8 @@ resource('/bots/:bot', { { ...botParams, ...await noContent("Deleted bot.") - } + }, + true ) }); @@ -120,7 +125,8 @@ resource('/bots/:bot/invite', { { ...botParams, ...await success("Public Bot", ref('PublicBot')) - } + }, + true ), post: routeAuthenticated( "Invite Public Bot", @@ -146,7 +152,8 @@ resource('/bots/:bot/invite', { ) `), ...await noContent("Added bot to server / group.") - } + }, + true ) }); //#endregion diff --git a/src/routes/channels.ts b/src/routes/channels.ts index da2ad64..0690166 100644 --- a/src/routes/channels.ts +++ b/src/routes/channels.ts @@ -397,7 +397,8 @@ resource('/channels/:channel/ack/:message', { { ...messageParams, ...await noContent("Acknowledged message.") - } + }, + true ) }); //#endregion @@ -446,7 +447,8 @@ resource('/channels/create', { } `), ...await success('Group', ref("GroupChannel")) - } + }, + true ) }); @@ -468,7 +470,8 @@ resource('/channels/:channel/members', { { ...messageParams, ...await noContent("User was added to the group.") - } + }, + true ), delete: routeAuthenticated( "Remove Group Member", @@ -476,7 +479,8 @@ resource('/channels/:channel/members', { { ...messageParams, ...await noContent("User was removed from the group.") - } + }, + true ) }); //#endregion diff --git a/src/routes/core.ts b/src/routes/core.ts index ae30350..f77ef2e 100644 --- a/src/routes/core.ts +++ b/src/routes/core.ts @@ -26,7 +26,8 @@ resource('/onboard/hello', { await success( "Onboarding information.", ref("OnboardingInformation") - ) + ), + true ) }); @@ -48,6 +49,7 @@ resource('/onboard/complete', { } `), ...await noContent("Successfully set username") - } + }, + true ) }); diff --git a/src/routes/misc.ts b/src/routes/misc.ts index 08a9e43..be0f92a 100644 --- a/src/routes/misc.ts +++ b/src/routes/misc.ts @@ -37,7 +37,8 @@ resource('/invites/:invite', { server: Server } `) - } + }, + true ), delete: routeAuthenticated( "Delete Invite", @@ -69,7 +70,8 @@ resource('/sync/settings/fetch', { ...await success("Settings Data", schema` type ${'SettingsData'} = { [key: string]: [ number, string ] }; `) - } + }, + true ) }); @@ -94,7 +96,8 @@ resource('/sync/settings/set', { } `), ...await noContent("Successfully synced data.") - } + }, + true ) }); @@ -108,7 +111,8 @@ resource('/sync/unreads', { import type { ChannelUnread } from "./Sync"; type ${'FetchUnreads'} = ChannelUnread[]; ` - ) + ), + true ) }); //#endregion @@ -123,7 +127,8 @@ resource('/push/subscribe', { { ...await body("Web Push Subscription", ref("WebPushSubscription")), ...await noContent("Subscribed successfully.") - } + }, + true ) }); @@ -131,7 +136,8 @@ resource('/push/unsubscribe', { post: routeAuthenticated( "Unsubscribe", "Remove the Web Push subscription associated with the current session.", - await noContent("Unsubscribed successfully.") + await noContent("Unsubscribed successfully."), + true ) }); //#endregion diff --git a/src/routes/servers.ts b/src/routes/servers.ts index 340f16c..1d74f7e 100644 --- a/src/routes/servers.ts +++ b/src/routes/servers.ts @@ -119,7 +119,8 @@ resource('/servers/create', { } `), ...await success('Server', ref("Server")) - } + }, + true ) }); @@ -202,7 +203,8 @@ resource('/servers/:server/ack', { { ...serverParams, ...await noContent("Marked as read.") - } + }, + true ), }); //#endregion diff --git a/src/routes/users.ts b/src/routes/users.ts index 6c4d846..f2a4ea1 100644 --- a/src/routes/users.ts +++ b/src/routes/users.ts @@ -89,7 +89,8 @@ resource('/users/@me/username', { } `), ...await noContent("Succesfully changed user object.") - } + }, + true ) }); @@ -200,7 +201,8 @@ resource('/users/relationships', { import type { Relationship } from "./Users"; type ${'FetchRelationships'} = Relationship[]; ` - ) + ), + true ) }); @@ -214,7 +216,8 @@ resource('/users/:user/relationship', { "Your relationship with the user.", ref("RelationshipOnly") ) - } + }, + true ) }); @@ -234,7 +237,8 @@ resource('/users/:username/friend', { "Sent friend request / added user as friend.", ref("RelationshipOnly") ) - } + }, + true ), delete: routeAuthenticated( "Deny Friend Request / Remove Friend", @@ -245,7 +249,8 @@ resource('/users/:username/friend', { "Deleted friend request / removed user from friends.", ref("RelationshipOnly") ) - } + }, + true ) }); @@ -259,7 +264,8 @@ resource('/users/:user/block', { "Blocked user.", ref("RelationshipOnly") ) - } + }, + true ), delete: routeAuthenticated( "Unblock User", @@ -270,7 +276,8 @@ resource('/users/:user/block', { "Unblocked user.", ref("RelationshipOnly") ) - } + }, + true ) }); //#endregion diff --git a/types/Auth.ts b/types/Auth.ts index 789fd40..daa7314 100644 --- a/types/Auth.ts +++ b/types/Auth.ts @@ -4,7 +4,7 @@ export interface Account { /** * User ID */ - id: Id; + _id: Id; /** * User Email @@ -16,7 +16,7 @@ export interface Session { /** * Session ID */ - id?: Id; + _id?: Id; /** * User ID @@ -26,5 +26,27 @@ export interface Session { /** * @maxLength 64 */ - session_token: string; + token: string; + + /** + * Device name + */ + name: string; + + /** + * Web Push subscription + */ + subscription?: string; +} + +export interface SessionInfo { + /** + * Session ID + */ + _id?: Id; + + /** + * Device name + */ + name: string; }