mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-21 04:25:27 -04:00
Update to rAuth v1.
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "revolt.js",
|
||||
"version": "5.0.1-alpha.7-patch.0",
|
||||
"version": "5.1.0-alpha.0",
|
||||
"main": "dist/index.js",
|
||||
"repository": "https://gitlab.insrt.uk/revolt/revolt.js",
|
||||
"author": "Paul Makles <insrt.uk>",
|
||||
@@ -30,7 +30,7 @@
|
||||
"in-publish": "^2.0.1",
|
||||
"jsdoc-babel": "^0.5.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"revolt-api": "^0.5.2-alpha.0",
|
||||
"revolt-api": "0.5.3-alpha.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"typedoc": "^0.21.4",
|
||||
"typescript": "^4.2.3"
|
||||
|
||||
+6
-9
@@ -223,8 +223,7 @@ export class Client extends EventEmitter {
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
'x-user-id': session?.user_id,
|
||||
'x-session-token': session?.session_token
|
||||
'x-session-token': session?.token
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,9 +233,9 @@ export class Client extends EventEmitter {
|
||||
* @param details Login data object
|
||||
* @returns An onboarding function if onboarding is required, undefined otherwise
|
||||
*/
|
||||
async login(details: Route<'POST', '/auth/login'>["data"]) {
|
||||
async login(details: Route<'POST', '/auth/session/login'>["data"]) {
|
||||
await this.fetchConfiguration();
|
||||
this.session = await this.req('POST', '/auth/login', details);
|
||||
this.session = await this.req('POST', '/auth/session/login', details);
|
||||
|
||||
return await this.$connect();
|
||||
}
|
||||
@@ -248,7 +247,6 @@ export class Client extends EventEmitter {
|
||||
*/
|
||||
async useExistingSession(session: Session) {
|
||||
await this.fetchConfiguration();
|
||||
await this.request('GET', '/auth/check', { headers: this.$generateHeaders(session) });
|
||||
this.session = session;
|
||||
return await this.$connect();
|
||||
}
|
||||
@@ -360,7 +358,7 @@ export class Client extends EventEmitter {
|
||||
*/
|
||||
async logout() {
|
||||
this.websocket.disconnect();
|
||||
await this.req('GET', '/auth/logout');
|
||||
await this.req('POST', '/auth/session/logout');
|
||||
this.reset();
|
||||
}
|
||||
|
||||
@@ -382,12 +380,11 @@ export class Client extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Register for a new account.
|
||||
* @param apiURL Base URL for the API of the server, such as https://api.revolt.example
|
||||
* @param data Registration data object
|
||||
* @returns A promise containing a registration response object
|
||||
*/
|
||||
register(apiURL: string, data: Route<'POST', '/auth/create'>["data"]) {
|
||||
return this.request('POST', '/auth/create', { data, baseURL: apiURL });
|
||||
register(data: Route<'POST', '/auth/account/create'>["data"]) {
|
||||
return this.request('POST', '/auth/account/create', { data });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+65
-58
@@ -5,6 +5,7 @@ import type { RetrievedInvite, ServerInvite } from 'revolt-api/types/Invites'
|
||||
import type { Profile, Relationship, RelationshipOnly, Status, User } from 'revolt-api/types/Users';
|
||||
import type { Ban, Category, Member, PermissionTuple, Server, SystemMessageChannels } from 'revolt-api/types/Servers';
|
||||
import type { Channel, DirectMessageChannel, GroupChannel, Message, TextChannel, VoiceChannel } from 'revolt-api/types/Channels';
|
||||
import { SessionInfo } from 'revolt-api/types/Auth';
|
||||
|
||||
export type RemoveUserField = 'ProfileContent' | 'ProfileBackground' | 'StatusText' | 'Avatar';
|
||||
export type RemoveChannelField = 'Icon' | 'Description';
|
||||
@@ -28,63 +29,28 @@ type Routes =
|
||||
* Auth
|
||||
*/
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/create`,
|
||||
data: {
|
||||
email: string,
|
||||
password: string,
|
||||
invite?: string,
|
||||
captcha?: string
|
||||
}
|
||||
method: 'GET',
|
||||
route: `/auth/account`,
|
||||
data: undefined,
|
||||
response: {
|
||||
_id: string,
|
||||
user_id: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/login`,
|
||||
route: `/auth/account/create`,
|
||||
data: {
|
||||
email: string,
|
||||
password: string,
|
||||
device_name?: string,
|
||||
invite?: string,
|
||||
captcha?: string
|
||||
}
|
||||
response: {
|
||||
id: string,
|
||||
user_id: string,
|
||||
session_token: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
method: 'GET',
|
||||
route: `/auth/user`,
|
||||
data: undefined
|
||||
response: {
|
||||
id: string,
|
||||
email: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/change/password`,
|
||||
data: {
|
||||
password: string,
|
||||
new_password: string
|
||||
},
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/change/email`,
|
||||
data: {
|
||||
password: string,
|
||||
new_email: string
|
||||
},
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/resend`,
|
||||
route: `/auth/account/reverify`,
|
||||
data: {
|
||||
email: string,
|
||||
captcha?: string
|
||||
@@ -93,7 +59,13 @@ type Routes =
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/send_reset`,
|
||||
route: `/auth/account/verify/:code`,
|
||||
data: undefined,
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/account/reset_password`,
|
||||
data: {
|
||||
email: string,
|
||||
captcha?: string
|
||||
@@ -101,8 +73,8 @@ type Routes =
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/reset`,
|
||||
method: 'PATCH',
|
||||
route: `/auth/account/reset_password`,
|
||||
data: {
|
||||
password: string,
|
||||
token: string
|
||||
@@ -111,29 +83,64 @@ type Routes =
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/check`,
|
||||
data: undefined
|
||||
route: `/auth/account/change/password`,
|
||||
data: {
|
||||
password: string,
|
||||
current_password: string
|
||||
},
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/account/change/email`,
|
||||
data: {
|
||||
email: string,
|
||||
current_password: string
|
||||
},
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/session/login`,
|
||||
data: {
|
||||
email: string,
|
||||
password?: string,
|
||||
challenge?: string,
|
||||
friendly_name?: string,
|
||||
captcha?: string
|
||||
},
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'POST',
|
||||
route: `/auth/session/logout`,
|
||||
data: undefined,
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'PATCH',
|
||||
route: `/auth/session/${Id}`,
|
||||
data: {
|
||||
friendly_name: string
|
||||
},
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'DELETE',
|
||||
route: `/auth/sessions/${Id}`,
|
||||
data: undefined
|
||||
route: `/auth/session/${Id}`,
|
||||
data: undefined,
|
||||
response: undefined
|
||||
}
|
||||
| {
|
||||
method: 'GET',
|
||||
route: `/auth/sessions`,
|
||||
data: undefined
|
||||
response: {
|
||||
id: string,
|
||||
friendly_name: string
|
||||
}[]
|
||||
route: `/auth/session/all`,
|
||||
data: undefined,
|
||||
response: SessionInfo[]
|
||||
}
|
||||
| {
|
||||
method: 'GET',
|
||||
route: `/auth/logout`,
|
||||
data: undefined
|
||||
method: 'DELETE',
|
||||
route: `/auth/session/all`,
|
||||
data: undefined,
|
||||
response: undefined
|
||||
}
|
||||
/**
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export const LIBRARY_VERSION = '5.0.1-alpha.7-patch.0';
|
||||
export const LIBRARY_VERSION = '5.1.0-alpha.0';
|
||||
|
||||
export const defaultConfig = {
|
||||
apiURL: 'https://api.revolt.chat',
|
||||
|
||||
+3
-2
@@ -7,7 +7,8 @@ config();
|
||||
|
||||
function user() {
|
||||
let client = new Client({
|
||||
apiURL: process.env.API_URL
|
||||
apiURL: process.env.API_URL,
|
||||
debug: true
|
||||
});
|
||||
|
||||
client.on('ready', async () => {
|
||||
@@ -39,7 +40,7 @@ function user() {
|
||||
}
|
||||
});
|
||||
|
||||
client.login({ email: process.env.EMAIL as string, password: process.env.PASSWORD as string })
|
||||
// client.login({ email: process.env.EMAIL as string, password: process.env.PASSWORD as string })
|
||||
}
|
||||
|
||||
function bot() {
|
||||
|
||||
@@ -2014,10 +2014,10 @@ ret@~0.1.10:
|
||||
resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
|
||||
integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==
|
||||
|
||||
revolt-api@^0.5.2-alpha.0:
|
||||
version "0.5.2-alpha.0"
|
||||
resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.2-alpha.0.tgz#a41f44ee38622636c9b5b5843f9e2798a79f00d3"
|
||||
integrity sha512-VI/o4nQTPXrDCVdFpZFfZfj7Q4nunj62gftdmYJtuSmXx+6eN2Nve7QQZjNt6UIH6Dc/IDgiFDcBdafBF9YXug==
|
||||
revolt-api@0.5.3-alpha.0:
|
||||
version "0.5.3-alpha.0"
|
||||
resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.3-alpha.0.tgz#4e093e09bf7dc4f4fdec50c35b6d4cff7e7cdbfb"
|
||||
integrity sha512-EB911QIBMIetM+wBozHYawoeO3GDei4UsxXD1YV13ldZ6l7/BWe0X7kax/zCVZFcC0cE5mxr3eizN+iYNV/boA==
|
||||
|
||||
rimraf@^3.0.2:
|
||||
version "3.0.2"
|
||||
|
||||
Reference in New Issue
Block a user