mirror of
https://github.com/stoatchat/javascript-client-api.git
synced 2026-08-26 12:35:48 -04:00
Migrate to rAuth v1.
This commit is contained in:
+1260
-497
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -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",
|
||||
|
||||
+3
-9
@@ -12,7 +12,7 @@ import './routes/index.js';
|
||||
|
||||
async function generate(): Promise<Document> {
|
||||
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<Document> {
|
||||
],
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,12 +50,15 @@ export function route(summary: string, description: string, obj: Omit<OpenAPIV3.
|
||||
}
|
||||
}
|
||||
|
||||
export function routeAuthenticated(summary: string, description: string, obj: Omit<OpenAPIV3.OperationObject, 'summary' | 'tags'>): OpenAPIV3.OperationObject {
|
||||
export function routeAuthenticated(summary: string, description: string, obj: Omit<OpenAPIV3.OperationObject, 'summary' | 'tags'>, disallowBots?: boolean): OpenAPIV3.OperationObject {
|
||||
return {
|
||||
...route(summary, description, obj),
|
||||
security: [
|
||||
security: disallowBots ? [
|
||||
{
|
||||
'Session Token': []
|
||||
}
|
||||
] : [
|
||||
{
|
||||
'User ID': [],
|
||||
'Session Token': []
|
||||
},
|
||||
{
|
||||
|
||||
+151
-127
@@ -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
|
||||
+14
-7
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+4
-2
@@ -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
|
||||
)
|
||||
});
|
||||
|
||||
+12
-6
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+14
-7
@@ -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
|
||||
|
||||
+25
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user